Islands Tour

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

There are beautiful islands connected with zip-lines. A tourist can go from one island to another island sliding through a zip-line that connects the islands. Sliding through a zip-line above sunset sea, a tourist can see breathtaking sceneries of nature with twinkling lights over the sunlit sea waters. These islands are fantastic attractions among tourists. Each island is full of flowers of numerous colors. Travelling from an arbitrary island, a tourist called Optimizer wants to visit as many distinct islands as possible.

The islands are represented as a directed graph G(V,E)G(V, E). A zip-line from an island vv to another island ww is represented as a directed edge (v,w)E(v, w) ∈ E. We assume that each island has at most one outgoing zip-line, that is, for each vertex vVv ∈ V, we have at most one outgoing edge.

For example, the figure below shows an example of the islands represented as a directed graph.

The dotted path in the following graph denotes a longest tour that visits as many distinct islands as possible.

Given a directed graph G(V,E)G(V, E) that represents the islands and their connections using zip-lines, write a program to output the maximum number of islands that can be visited by Optimizer. Note that Optimizer can start from an arbitrary island and cannot visit the same island twice or more.

입력

Your program is to read from standard input. The input starts with a line containing two integers, mm and nn (0mn1,000,0000 ≤ m ≤ n ≤ 1\\,000\\,000), where mm is the number of zip-line connections (edges) and nn is the number of islands (vertices). The islands are numbered from 00 to n1n - 1. In the following mm lines, the ii-th line contains two integers v_iv\_i and w_iw\_i that represent a directed edge (v_i,w_i)(v\_i , w\_i) from v_iv\_i to w_iw\_i. We assume that each vertex has at most one outgoing edge.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the maximum number of distinct islands that can be visited by riding zip-lines starting from an arbitrary island.