Problem: There is a grid of squares with H+1 horizontal rows and W vertical columns.

You will start at one of the squares in the top row and repeat moving one square right or down. However, for each integer i from 1 through H, you cannot move down from the A_i-th, (A_i + 1)-th, \ldots, B_i-th squares from the left in the i-th row from the top.

For each integer k from 1 through H, find the minimum number of moves needed to reach one of the squares in the (k+1)-th row from the top. (The starting square can be chosen individually for each case.) If, starting from any square in the top row, none of the squares in the (k+1)-th row can be reached, print `-1` instead.

Constraints

* 1 \leq H,W \leq 2\times 10^5
* 1 \leq A_i \leq B_i \leq W

Input

Input is given from Standard Input in the following format:


H W
A_1 B_1
A_2 B_2
:
A_H B_H


Output

Print H lines. The i-th line should contain the answer for the case k=i.

Example

Input

4 4
2 4
1 1
2 3
2 4


Output

1
3
6
-1

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.SortedMap;
import java.util.TreeMap;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] head = br.readLine().split(" ");
    int h = Integer.parseInt(head[0]);
    int w = Integer.parseInt(head[1]);
    int[][] ab = new int[h][2];
    for(int i = 0; i < h; i++){
      String[] data = br.readLine().split(" ");
      ab[i][0] = Integer.parseInt(data[0]);
      ab[i][1] = Integer.parseInt(data[1]);
    }
    br.close();

    // key:終点のH座標、value:始点のH座標
    SortedMap<Integer, Integer> routeMap = new TreeMap<>();
    SortedMap<Integer, Integer> distMap = new TreeMap<>();

    for(int num = 1; num <= w; num++){
      routeMap.put(num, num);
    }
    distMap.put(0, w);

    PrintWriter pw = new PrintWriter(System.out);
    for(int i = 0; i < h; i++){
      int from = ab[i][0];
      int to = ab[i][1];
      SortedMap<Integer, Integer> subMap = routeMap.subMap(from, to + 1);
      if(to < w && !routeMap.containsKey(to + 1) && !subMap.isEmpty()){
        int dist = to + 1 - subMap.get(subMap.lastKey());
        routeMap.put(to + 1, subMap.get(subMap.lastKey()));
        if(distMap.containsKey(dist)){
          distMap.put(dist, distMap.get(dist) + 1);
        } else {
          distMap.put(dist, 1);
        }
      }
      for(Integer key : subMap.keySet()){
        int dist = key - subMap.get(key);
        if(distMap.get(dist) == 1){
          distMap.remove(dist);
        } else {
          distMap.put(dist, distMap.get(dist) - 1);
        }
      }
      subMap.clear();

      if(distMap.isEmpty()){
        pw.println(-1);
      } else {
        pw.println(distMap.firstKey() + i + 1);
      }
    }
    pw.close();
  }
}