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 CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  int h, w;
  fscanf(stdin, "%d%d ", &h, &w);
  multiset<int> hd; // horizontal distance between from start to current position
  map<int, int> hdmap; // (current column, start column) to obtain the answer in log(n)
  REP(i,w) {
    hdmap[i] = i;
    hd.insert(0);
  }
  REP(i,h) {
    int l, r;
    fscanf(stdin, "%d%d ", &l, &r);
    --l; // semiopen interval [l-1, r) based on 0-index
    auto it = hdmap.lower_bound(l);
    int re = -1;
    while (it != hdmap.end() && it->first <= r) {
      re = max(re, it->second);
      hd.erase(hd.find(it->first - it->second));
      hdmap.erase(it++);
    }
    // the only optimal start point in [l-1, r) remains
    if (re != -1 && r < w) {
      hd.insert(r-re);
      hdmap[r] = re;
    }
    int res = -1;
    if (hd.size()) res = *hd.begin() + (i+1);
    fprintf(stdout, "%d\n", res);
  }
  return 0;
}