A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).

Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?

No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.

Input

The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).

Output

Print the maximal number of orders that can be accepted.

Examples

Input

2
7 11
4 7


Output

1


Input

5
1 2
2 3
3 4
4 5
5 6


Output

3


Input

6
4 8
1 5
4 7
2 5
1 3
6 8


Output

2
#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;
long long fact(long long n) {
  long long ans = 1;
  for (long long i = 1; i <= n; i++) ans = (ans * i) % MOD;
  return ans;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
long long ModPow(long long a, long long b, long long M) {
  if (M == 1) return 0;
  a %= M;
  long long ans = 1, t = 1;
  while (t > 0 && t <= b) {
    if (t & b) {
      ans *= a;
      ans %= M;
    }
    t <<= 1;
    a *= a;
    a %= M;
  }
  return ans;
}
long long modInverse(long long n, long long p) { return ModPow(n, p - 2, p); }
long long nCrModP(long long n, long long r, long long p) {
  if (n < r) return 0;
  if (r == 0) return 1;
  long long fac[n + 1];
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
void edgeU(vector<int> G[], int source, int dest) {
  G[source].push_back(dest);
  G[dest].push_back(source);
}
void edgeD(vector<int> G[], int source, int dest) { G[source].push_back(dest); }
void print_G(vector<int> G[], int v) {
  for (long long i = 0; i < v; i++) {
    cout << i << " --> ";
    for (long long j = 0; j < G[i].size(); j++) {
      cout << G[i][j] << " ";
    }
    cout << "\n";
  }
}
void BFS(vector<int> G[], int s, int v, int& V, int& E) {
  vector<int> visited(v, 0);
  vector<int> parent(v, -1);
  vector<int> dist(v, INT_MAX);
  V = 1, E = G[s].size();
  visited[s] = 1;
  dist[s] = 0;
  queue<int> q;
  q.push(s);
  while (q.empty() == false) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      if (visited[G[u][i]] == 0) {
        visited[G[u][i]] = 1;
        V++;
        E += G[G[u][i]].size();
        q.push(G[u][i]);
      }
    }
  }
}
void DFSvisit(vector<int> G[], int u, vector<int>& visited, vector<int>& start,
              vector<int>& finish, int& t) {
  visited[u] = 1;
  start[u] = t++;
  for (int i = 0; i < G[u].size(); i++) {
    if (visited[G[u][i]] == 0) DFSvisit(G, G[u][i], visited, start, finish, t);
  }
  visited[u] = 2;
  finish[u] = t++;
}
void DFS(vector<int> G[], int v, vector<int>& verc, vector<int>& ec) {
  vector<int> visited(v, 0);
  vector<int> start(v, 0), finish(v, 0);
  int t = 0;
  for (int i = 0; i < v; i++) {
    if (visited[i] == 0) DFSvisit(G, i, visited, start, finish, t);
  }
}
int aux(vector<int>& a, int p, int r) {
  int ma = a[p], ind = p;
  for (int i = p; i <= r; i++) {
    if (a[i] > ma) {
      ma = a[i];
      ind = i;
    }
  }
  return ind;
}
void MAX(vector<int>& a, int p, int r, int d, vector<int>& ans) {
  if (p <= r) {
    int q = aux(a, p, r);
    ans[q] = d;
    MAX(a, p, q - 1, d + 1, ans);
    MAX(a, q + 1, r, d + 1, ans);
  }
}
bool Comparator(int a, int b) { return (a >= b); }
bool check(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    return false;
  else
    return true;
}
void v_out(vector<int>& ans) {
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << "\n";
}
void v_outd(vector<double>& ans) {
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << "\n";
}
string solve() {
  int n, s, f;
  cin >> n;
  vector<pair<int, int> > t;
  for (long long i = 0; i < n; i++) {
    cin >> s >> f;
    t.push_back({f, s});
  }
  sort(t.begin(), t.end());
  int cur = 0, ans = 0;
  for (long long i = 0; i < n; i++) {
    if (t[i].second > cur) {
      cur = t[i].first;
      ans++;
    }
  }
  cout << ans;
  return "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    cout << solve();
  }
  return 0;
}
