Under construction

Still being built. Things may change

Roads are not a luxury but a way to travel

Time limit2sMemory limit1024 MB

Summary
After each one-way road is added to a DAG, find the fewest vertex-disjoint routes that together visit every city exactly once.
Level

Medium7 of 10

Topics
Graph, DFS, BFS
Solved
No attempts yet

Problem

Country N has nn cities, numbered from 1 to nn, but it has no roads at all. The president has decided to build mm roads over mm days, one new road per day. To encourage migration, every road is one-way, and the road network is planned so that if there is a path from city ii to city jj, there is no path from city jj to city ii.

To promote the new roads, country N holds a series of test drives through its cities every day. Each car starts in some city, drives along the roads built so far, and ends in some city. A car may start and end in the same city, in which case it drives no roads. To please residents and save drivers' fuel, the organizers choose the set of routes each day under these rules:

  1. Every city must be visited by a car. A city counts as visited if it is the start, the end, or an intermediate city of any car's route.
  2. No city may be visited more than once by the cars.
  3. The total number of cars used must be minimal.

The transport ministry of country N has already scheduled the construction of exactly one road for each of the next mm days. For each day, the ministry asks you to find the minimum number of cars needed for the test drives. On day ii, all roads built on days 1,2,…,i1, 2, \ldots, i are available.

Input

The first line contains two integers nn and mm (2≤n≤10002 \leq n \leq 1000, 1≤m≤100 0001 \leq m \leq 100\,000), the number of cities and the number of days. Each of the next mm lines contains two integers uiu_i and viv_i (1≤ui,vi≤n1 \leq u_i, v_i \leq n, ui≠viu_i \neq v_i), meaning that on day ii a one-way road from city uiu_i to city viv_i is built. A road may be built between two cities that are already connected by a road. It is guaranteed that after each road is built, if there is a path from city aa to city bb, then there is no path from city bb to city aa.

Output

Print mm numbers. The ii-th number is the minimum number of cars needed after the first ii roads are built.

Hint

In the first example, even after the first two roads are built, at least two cars are still needed. For instance, one car can drive from city 1 to city 2, and another car can start and finish in city 3. After all roads are built, one car is enough: it drives along 1→2→31 \rightarrow 2 \rightarrow 3.

In the second example, after all roads are built, two cars could visit all cities, but the rule that no city may be visited more than once rules this out.

Examples3

  1. Example 1

    Input
    3 3
    1 2
    1 3
    2 3
    
    Expected output
    2 2 1
    
  2. Example 2

    Input
    5 4
    1 2
    2 3
    4 2
    2 5
    
    Expected output
    4 3 3 3
    
  3. Example 3

    Input
    4 4
    1 2
    1 2
    3 4
    3 4
    
    Expected output
    3 3 2 2