#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
char buffer[maxn], *S, *TT;
inline char Get_Char() {
  if (S == TT) {
    TT = (S = buffer) + fread(buffer, 1, maxn, stdin);
    if (S == TT) return EOF;
  }
  return *S++;
}
inline int read() {
  char c;
  int re = 0, f = 0;
  for (c = Get_Char(); c < '0' or c > '9'; c = Get_Char())
    if (c == '-') f = 1;
  for (; c >= '0' and c <= '9';)
    re = (re << 1) + (re << 3) + (c - '0'), c = Get_Char();
  if (f) return -re;
  return re;
}
inline void read(int &x) {
  char c;
  int re = 0, f = 0;
  for (c = Get_Char(); c < '0' or c > '9'; c = Get_Char())
    if (c == '-') f = 1;
  for (; c >= '0' and c <= '9';)
    re = (re << 1) + (re << 3) + (c - '0'), c = Get_Char();
  if (f)
    x = -re;
  else
    x = re;
}
inline void _swap(int &x, int &y) { x ^= y ^= x ^= y; }
inline int _abs(const int &x) { return x > 0 ? x : -x; }
inline int _max(const int &x, const int &y) { return x > y ? x : y; }
inline int _min(const int &x, const int &y) { return x < y ? x : y; }
const int N = 3e5 + 5;
namespace treap {
struct Treap {
  struct node {
    int son[2], va, pri, siz, laz;
  } tr[N];
  int st[N], top, tot;
  int rt;
  inline void pushup(const int &x) {
    tr[x].siz = tr[tr[x].son[0]].siz + tr[tr[x].son[1]].siz + 1;
  }
  inline int newnode(const int &va) {
    int cnt;
    if (top)
      cnt = st[top--];
    else
      cnt = ++tot;
    tr[cnt].va = va, tr[cnt].son[0] = tr[cnt].son[1] = tr[cnt].laz = 0,
    tr[cnt].siz = 1, tr[cnt].pri = rand();
    return cnt;
  }
  inline void change(const int &x, const int &va) {
    if (!x) return;
    tr[x].laz += va, tr[x].va += va;
  }
  inline void pushdown(const int &x) {
    if (!x or !tr[x].laz) return;
    change(tr[x].son[0], tr[x].laz), change(tr[x].son[1], tr[x].laz);
    tr[x].laz = 0;
  }
  int merge(const int &x, const int &y) {
    if (!x or !y) return x + y;
    pushdown(x), pushdown(y);
    if (tr[x].pri < tr[y].pri) {
      tr[x].son[1] = merge(tr[x].son[1], y);
      pushup(x);
      return x;
    } else {
      tr[y].son[0] = merge(x, tr[y].son[0]);
      pushup(y);
      return y;
    }
  }
  void split(int now, int k, int &x, int &y) {
    if (!now) {
      x = y = 0;
      return;
    }
    pushdown(now);
    if (tr[now].va <= k)
      x = now, split(tr[now].son[1], k, tr[now].son[1], y);
    else
      y = now, split(tr[now].son[0], k, x, tr[now].son[0]);
    pushup(now);
  }
  inline int kth(int now, int k) {
    if (!k) return 0;
    for (;;) {
      if (tr[tr[now].son[0]].siz == k - 1) return now;
      if (tr[tr[now].son[0]].siz >= k)
        now = tr[now].son[0];
      else
        k -= tr[tr[now].son[0]].siz + 1, now = tr[now].son[1];
    }
  }
  inline int pre(const int &va) {
    int a, b, ret;
    split(rt, va - 1, a, b), ret = kth(a, tr[a].siz), rt = merge(a, b);
    return ret;
  }
  inline int nxt(const int &va) {
    int a, b, ret;
    split(rt, va, a, b), ret = kth(b, 1), rt = merge(a, b);
    return ret;
  }
  inline void insert(const int &va) {
    int a, b;
    split(rt, va, a, b), rt = merge(merge(a, newnode(va)), b);
  }
  inline void del(const int &va) {
    int a, b, c, d;
    split(rt, va, a, b), split(a, va - 1, c, d),
        st[++top] = d, d = merge(tr[d].son[0], tr[d].son[1]),
        rt = merge(merge(c, d), b);
  }
  inline void modify(const int &l, const int &r) {
    int a, b, c, d;
    split(rt, l - 1, a, b), split(b, r, c, d), change(c, 1),
        rt = merge(a, merge(c, d));
  }
};
}  // namespace treap
int n, dp[N];
treap::Treap T;
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    read(l), read(r);
    if (i == 1)
      T.insert(l);
    else {
      int t = T.nxt(r - 1);
      T.modify(l, r - 1);
      if (t) T.del(T.tr[t].va);
      T.insert(l);
    }
  }
  if (!T.rt)
    return puts("0") * 0;
  else
    cout << T.tr[T.rt].siz << '\n';
}

### Prompt

Create a solution in CPP for the following problem:

Leha and Noora decided to go on a trip in the Baltic States. As you know from the previous problem, Leha has lost his car on the parking of the restaurant. Unfortunately, requests to the watchman didn't helped hacker find the car, so friends decided to go hitchhiking.

In total, they intended to visit n towns. However it turned out that sights in i-th town are open for visitors only on days from li to ri.

What to do? Leha proposed to choose for each town i a day, when they will visit this town, i.e any integer xi in interval [li, ri]. After that Noora choses some subsequence of towns id1, id2, ..., idk, which friends are going to visit, that at first they are strictly increasing, i.e idi < idi + 1 is for all integers i from 1 to k - 1, but also the dates of the friends visits are strictly increasing, i.e xidi < xidi + 1 is true for all integers i from 1 to k - 1.

Please help Leha and Noora in choosing such xi for each town i, and such subsequence of towns id1, id2, ..., idk, so that friends can visit maximal number of towns.

You may assume, that Leha and Noora can start the trip any day.

Input

The first line contains a single integer n (1 ≤ n ≤ 3·105) denoting the number of towns Leha and Noora intended to visit.

Each line i of the n subsequent lines contains two integers li, ri (1 ≤ li ≤ ri ≤ 109), denoting that sights in i-th town are open for visitors on any day <image>.

Output

Print a single integer denoting the maximal number of towns, that Leha and Noora can visit.

Example

Input

5
6 6
1 2
3 4
2 2
1 4


Output

3

Note

Consider the first example.

Let's take this plan: let's visit the sight in the second town on the first day, in the third town on the third day and in the fifth town on the fourth. That's would be the optimal answer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
char buffer[maxn], *S, *TT;
inline char Get_Char() {
  if (S == TT) {
    TT = (S = buffer) + fread(buffer, 1, maxn, stdin);
    if (S == TT) return EOF;
  }
  return *S++;
}
inline int read() {
  char c;
  int re = 0, f = 0;
  for (c = Get_Char(); c < '0' or c > '9'; c = Get_Char())
    if (c == '-') f = 1;
  for (; c >= '0' and c <= '9';)
    re = (re << 1) + (re << 3) + (c - '0'), c = Get_Char();
  if (f) return -re;
  return re;
}
inline void read(int &x) {
  char c;
  int re = 0, f = 0;
  for (c = Get_Char(); c < '0' or c > '9'; c = Get_Char())
    if (c == '-') f = 1;
  for (; c >= '0' and c <= '9';)
    re = (re << 1) + (re << 3) + (c - '0'), c = Get_Char();
  if (f)
    x = -re;
  else
    x = re;
}
inline void _swap(int &x, int &y) { x ^= y ^= x ^= y; }
inline int _abs(const int &x) { return x > 0 ? x : -x; }
inline int _max(const int &x, const int &y) { return x > y ? x : y; }
inline int _min(const int &x, const int &y) { return x < y ? x : y; }
const int N = 3e5 + 5;
namespace treap {
struct Treap {
  struct node {
    int son[2], va, pri, siz, laz;
  } tr[N];
  int st[N], top, tot;
  int rt;
  inline void pushup(const int &x) {
    tr[x].siz = tr[tr[x].son[0]].siz + tr[tr[x].son[1]].siz + 1;
  }
  inline int newnode(const int &va) {
    int cnt;
    if (top)
      cnt = st[top--];
    else
      cnt = ++tot;
    tr[cnt].va = va, tr[cnt].son[0] = tr[cnt].son[1] = tr[cnt].laz = 0,
    tr[cnt].siz = 1, tr[cnt].pri = rand();
    return cnt;
  }
  inline void change(const int &x, const int &va) {
    if (!x) return;
    tr[x].laz += va, tr[x].va += va;
  }
  inline void pushdown(const int &x) {
    if (!x or !tr[x].laz) return;
    change(tr[x].son[0], tr[x].laz), change(tr[x].son[1], tr[x].laz);
    tr[x].laz = 0;
  }
  int merge(const int &x, const int &y) {
    if (!x or !y) return x + y;
    pushdown(x), pushdown(y);
    if (tr[x].pri < tr[y].pri) {
      tr[x].son[1] = merge(tr[x].son[1], y);
      pushup(x);
      return x;
    } else {
      tr[y].son[0] = merge(x, tr[y].son[0]);
      pushup(y);
      return y;
    }
  }
  void split(int now, int k, int &x, int &y) {
    if (!now) {
      x = y = 0;
      return;
    }
    pushdown(now);
    if (tr[now].va <= k)
      x = now, split(tr[now].son[1], k, tr[now].son[1], y);
    else
      y = now, split(tr[now].son[0], k, x, tr[now].son[0]);
    pushup(now);
  }
  inline int kth(int now, int k) {
    if (!k) return 0;
    for (;;) {
      if (tr[tr[now].son[0]].siz == k - 1) return now;
      if (tr[tr[now].son[0]].siz >= k)
        now = tr[now].son[0];
      else
        k -= tr[tr[now].son[0]].siz + 1, now = tr[now].son[1];
    }
  }
  inline int pre(const int &va) {
    int a, b, ret;
    split(rt, va - 1, a, b), ret = kth(a, tr[a].siz), rt = merge(a, b);
    return ret;
  }
  inline int nxt(const int &va) {
    int a, b, ret;
    split(rt, va, a, b), ret = kth(b, 1), rt = merge(a, b);
    return ret;
  }
  inline void insert(const int &va) {
    int a, b;
    split(rt, va, a, b), rt = merge(merge(a, newnode(va)), b);
  }
  inline void del(const int &va) {
    int a, b, c, d;
    split(rt, va, a, b), split(a, va - 1, c, d),
        st[++top] = d, d = merge(tr[d].son[0], tr[d].son[1]),
        rt = merge(merge(c, d), b);
  }
  inline void modify(const int &l, const int &r) {
    int a, b, c, d;
    split(rt, l - 1, a, b), split(b, r, c, d), change(c, 1),
        rt = merge(a, merge(c, d));
  }
};
}  // namespace treap
int n, dp[N];
treap::Treap T;
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    read(l), read(r);
    if (i == 1)
      T.insert(l);
    else {
      int t = T.nxt(r - 1);
      T.modify(l, r - 1);
      if (t) T.del(T.tr[t].va);
      T.insert(l);
    }
  }
  if (!T.rt)
    return puts("0") * 0;
  else
    cout << T.tr[T.rt].siz << '\n';
}

```