fabbbhgedd
 abbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaab
 hcdhgcchbdhbeagdcfedgcbaffebgcbcccadeefacbhefgeadfgchabgeebegahfgegahbddedfhffeadcedadgfbeebhgfahhfb
 khjcoijiicdkdianmdolmadobdkcmgifdnffddnjehhbldlkjffknficdcmokfacioiegjedbmadjioomdacbodcajcmonmnlabo
 bababbdaee
 cbbbbcaaca
 gaejllebhn
 eaaebccaeacdecaedcaabbbdeebccdcdaabeeaeeaddbaabdccebecebbbbedbdcbbbbbbecbaddcddcccdcbbadbecddecedbba
 difhjdjbcdjedhiegagdejkbjfcdcdagdijdjajecbheiabfbjdgjdecfhdkgdbkcgcgakkiiggfkgcfadkjhiijkjacgejfhjge
 bbababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbb
 cadbcdddda
 kpsaloedscghjeaqadfhmlibjepjafdomkkorinrpakondtnrnknbqarbejcenrlsbfgdbsdmkpphbkdnbitjfcofsjibssmmlll
 aaabbbaaaabbbbaaabbbbbaabbbbaaababbaaabbbbaaabbbbababbbbaaabbbbaaabbbbbaabbbbaaabbbbaaabbbb
 ibledofnibedebifmnjdoaijeghajecbkjaebbkofnacceaodiifbhgkihkibddneeiemacodeafeaiiiaoajhmkjffbmmiehebhokfklhbkeoanoajdedjdlkbhenidclagggfhhhldfleccgmjbkhaginlhabkabagikalccndciokabfaebjkndf
 abbacba
 jkeaagakbifeaechkifkdghcjcgighidcgdccfbdbcackfgaebkddabgijkhjkaffkabacekdkjekeccegbecbkecbgbgcacgdackcdfjefaifgbigahkbedidfhjbikejdhejcgideaeejdcegeeccaefbddejkbdkfagfcdjbikbidfggkidcdcic

1.000000000000000
 0.000000000000000
 0.450000000000000
 0.960000000000000
 1.000000000000000
 0.800000000000000
 1.000000000000000
 0.080000000000000
 0.840000000000000
 0.000000000000000
 0.800000000000000
 1.000000000000000
 0.000000000000000
 0.786096256684492
 1.000000000000000
 0.438502673796791

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 1e9 + 10;
int a[MAXN];
int x[MAXN];
int y[MAXN];
int dp[MAXN];
long long lk = 9999999;
int main() {
  lk -= 2;
  ios_base ::sync_with_stdio(false);
  lk -= 2;
  cin.tie(0);
  lk -= 2;
  int n, m, res = 0;
  lk -= 2;
  cin >> n >> m;
  lk -= 2;
  for (int i = 0; i < n; i++) {
    lk -= 2;
    int l, r;
    lk -= 2;
    cin >> l >> r;
    lk -= 2;
    a[r]++;
    lk -= 2;
    a[l - 1]--;
    lk -= 2;
  }
  for (int i = m; i >= 1; i--) {
    lk -= 2;
    a[i] += a[i + 1];
    lk -= 2;
  }
  fill(dp, dp + MAXN, INF);
  lk -= 2;
  lk -= 2;
  for (int i = 1; i <= m; i++) {
    lk -= 2;
    int w = upper_bound(dp + 1, dp + MAXN, a[i]) - dp;
    lk -= 2;
    dp[w] = a[i];
    lk -= 2;
    x[i] = w;
    lk -= 2;
  }
  fill(dp, dp + MAXN, INF);
  lk -= 2;
  lk -= 2;
  for (int i = m; i >= 1; i--) {
    lk -= 2;
    int w = upper_bound(dp + 1, dp + MAXN, a[i]) - dp;
    lk -= 2;
    dp[w] = a[i];
    lk -= 2;
    y[i] = w;
    lk -= 2;
    lk -= 2;
    res = max(res, x[i] + y[i] - 1);
    lk -= 2;
  }
  lk -= 2;
  cout << res;
  lk -= 2;
}
