Cereal

소들이 줄을 선 순서대로 좋아하는 시리얼을 먼저, 없으면 두 번째로 좋아하는 시리얼을 가져간다고 할 때, 앞에서 i마리를 제거한 각 경우에 시리얼을 받는 소의 수를 구한다.

어려움8그래프유니온 파인드구현그리디아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Farmer John's cows like nothing more than cereal for breakfast! In fact, the cows have such large appetites that they will each eat an entire box of cereal for a single meal.

The farm has recently received a shipment with MM different types of cereal (1M105)(1\le M\le 10^5) . Unfortunately, there is only one box of each cereal! Each of the NN cows (1N105)(1\le N\le 10^5) has a favorite cereal and a second favorite cereal. When given a selection of cereals to choose from, a cow performs the following process:

  1. If the box of her favorite cereal is still available, take it and leave.
  2. Otherwise, if the box of her second-favorite cereal is still available, take it and leave.
  3. Otherwise, she will moo with disappointment and leave without taking any cereal.

The cows have lined up to get cereal. For each 0iN10 \leq i \leq N-1, determine how many cows would take a box of cereal if Farmer John removed the first ii cows from the line.

입력

The first line contains two space-separated integers NN and M.M.

For each 1iN,1\le i\le N, the ii-th line contains two space-separted integers f_if\_i and s_is\_i (1f_i,s_iM1\le f\_i,s\_i\le M and f_is_if\_i\neq s\_i) denoting the favorite and second-favorite cereals of the ii-th cow in line.

출력

For each 0iN1,0\le i\le N-1, print a line containing the answer for i.i.

힌트

If at least two cows remain, then exactly two of them get a box of cereal.