#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e5 + 10;
class BIT {
  int a[N];

 public:
  void init() { memset((a), (0), sizeof(a)); }
  void add(int x, int val) {
    while (x < N) {
      a[x] = max(a[x], val);
      x += x & -x;
    }
  }
  int sum(int x) {
    int ret = 0;
    while (x) {
      ret = max(ret, a[x]);
      x -= x & -x;
    }
    return ret;
  }
} b;
int a[N];
int ans[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  swap(n, m);
  while (m--) {
    int l, r;
    scanf("%d%d", &l, &r);
    a[l]++;
    a[r + 1]--;
  }
  a[1]++;
  for (int i = 1; i <= n; i++) {
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    int x = b.sum(a[i]);
    ans[i] += x;
    b.add(a[i], x + 1);
  }
  b.init();
  for (int i = n; i >= 1; i--) {
    if (a[i] == 0) continue;
    int x = b.sum(a[i]);
    ans[i] += x;
    b.add(a[i], x + 1);
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    res = max(res, ans[i] + 1);
  }
  printf("%d\n", res);
  return 0;
}
