#include using namespace std; inline int read() { int x = 0, f = 0; char ch = getchar(); while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar(); while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return f ? -x : x; } int __stk[128], __top; inline void write(int x) { if(x < 0) putchar('-'), x = -x; do { __stk[++__top] = x % 10, x /= 10; } while (x); while (__top) putchar(__stk[__top--] + '0'); } const int mod = 998244353; void Min(int &x, int y) { y < x and (x = y); } void Max(int &x, int y) { y > x and (x = y); } void inc(int &x, int y) { (x += y) >= mod and (x -= mod); } void mul(int &x, int y) { x = 1ll * x * y % mod; } int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; } bool stmer; const int N = 1e6 + 10, M = 1e6; int n, rt, cnt, top; int t[N][2], fa[N], siz[N], s[N], tag[N], stk[N]; void update(int x) { siz[x] = siz[t[x][0]] + siz[t[x][1]] + 1; } void pushup(int x, int k) { tag[x] += k, s[x] += k; } void pushdown(int x) { pushup(t[x][0], tag[x]), pushup(t[x][1], tag[x]), tag[x] = 0; } int build(int l, int r) { if (l > r) return 0; int mid = (l + r) >> 1, x = ++cnt; t[x][0] = build(l, mid - 1), t[x][1] = build(mid + 1, r); return update(x), fa[t[x][0]] = fa[t[x][1]] = x; } int get(int x) { return t[fa[x]][1] == x; } void rotate(int x) { int f1 = fa[x], f2 = fa[f1], k = get(x); if (f2) t[f2][get(f1)] = x; fa[x] = f2; t[f1][k] = t[x][!k], fa[t[f1][k]] = f1; t[x][!k] = f1, fa[f1] = x; update(f1), update(x); } void splay(int x, int to = 0) { if (x == to) return; int p = stk[top = 1] = x; while (fa[p] ^ to) stk[++top] = p = fa[p]; while (top) pushdown(stk[top--]); for (int f; (f = fa[x]) ^ to; rotate(x)) if (fa[f] ^ to) rotate(get(x) == get(f) ? f : x); if (!to) rt = x; } int findrk(int k) { int x = rt; while (x) { pushdown(x); if (k <= siz[t[x][0]]) x = t[x][0]; else { k -= siz[t[x][0]] + 1; if (!k) return x; x = t[x][1]; } } } void split(int l, int r) { splay(findrk(l)), splay(findrk(r + 3), rt); } void out(int x) { if (!x) return; pushdown(x), out(t[x][0]); write(s[x]), putchar(' '); out(t[x][1]); } bool edmer; signed main() { // freopen("Yukicoder686.in", "r", stdin); // freopen("Yukicoder686.out", "w", stdout); cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n"; n = read(), rt = build(-1, M + 1); for (int i = 1; i <= n; i++) { int l = read(), r = read(), x, y, z; split(l, r), x = y = t[t[rt][1]][0]; while (t[y][0]) pushdown(y), y = t[y][0]; int val = s[y]; while (t[x][1]) pushdown(x), x = t[x][1]; y = fa[x], z = t[x][0], pushdown(x); t[y][y != t[rt][1]] = z, fa[z] = y, update(y); splay(z ? z : y, t[rt][1]); y = t[t[rt][1]][0], pushup(y, 1); while (t[y][0]) pushdown(y), y = t[y][0]; s[x] = val, tag[x] = 0, pushdown(y); t[x][0] = 0, siz[x] = 1, t[y][0] = x, fa[x] = y; update(y), splay(x, y = t[rt][1]); while (t[x][1]) pushdown(x), x = t[x][1]; if (s[y] < s[x]) { int lat = y; s[y]++, pushdown(y), y = t[y][1]; while (y) { lat = y, pushdown(y); if (s[y] >= s[x]) y = t[y][0]; else s[y]++, pushup(t[y][0], 1), y = t[y][1]; } splay(lat); } } int x = rt; while (t[x][1]) pushdown(x), x = t[x][1]; write(s[x]); cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n"; return 0; }