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;
string to_str(long long Number) {
  stringstream ss;
  ss << Number;
  return ss.str();
}
long long to_int(string str) {
  long long val;
  stringstream stream;
  stream << str;
  stream >> val;
  return val;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
string binary(long long n) {
  string result;
  do result.push_back('0' + (n & 1));
  while (n >>= 1);
  reverse(result.begin(), result.end());
  return result;
}
long long n, x, y, z, c, c1, c2, c3, k, k1, k2, t, arr;
int main() {
  cin >> n;
  vector<pair<long long, long long> > v;
  map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (m[x] == 0)
      m[x] = y;
    else
      m[x] = min(m[x], y);
  }
  map<long long, long long>::iterator it = m.begin();
  for (; it != m.end(); it++) {
    v.push_back({it->first, it->second});
  }
  sort(v.begin(), v.end());
  n = v.size();
  for (int i = 0; i < n - 1; i++) {
    x = v[i].second;
    c = 0;
    if (v[i + 1].second < x) {
      if (v[i + 2].first > v[i + 1].second && i + 2 < n) v.erase(v.begin() + i);
    }
  }
  x = v[0].second;
  for (int i = 1; i < v.size(); i++) {
    if (v[i].first > x) {
      x = v[i].second;
      c++;
    } else if (v[i].second != 0)
      x = min(x, v[i].second);
  }
  cout << c + 1;
  return 0;
}
