- Time limit: 1.00 s
- Memory limit: 512 MB
There are cities with airports but no flight connections. You are given requests which routes should be possible to travel.
Your task is to determine the minimum number of one-way flight connections which makes it possible to fulfil all requests.
Input
The first input line has two integers and : the number of cities and requests. The cities are numbered .
After this, there are lines describing the requests. Each line has two integers and : there has to be a route from city to city . Each request is unique.
Output
Print one integer: the minimum number of flight connections.
Constraints
Example
Input:
4 5 1 2 2 3 2 4 3 1 3 4
Output:
4
Explanation: You can create the connections , , and . Then you can also fly from city to city using the route .