#include <bits/stdc++.h>
using namespace std;
#define forn(i, k, e) for (int i = k; i < e; i++)
typedef pair<int, int> pii;
int32_t main() {
int n, k;
cin >> n >> k;
vector<pair<int, int>> movies;
forn(i, 0, n) {
int a, b;
cin >> a >> b;
movies.push_back({b, a}); // insert end time, start time
}
sort(movies.begin(), movies.end()); // sort based on end time
int count = 0;
priority_queue<int, vector<int>, greater<int>> end; // min heap to store min end times on top
forn(i, 0, k) end.push(0);
forn(i, 0, n) {
pii cur = movies[i];
if(end.top() > cur.second) continue; // movie ends after cur movie starts
end.pop();
end.push(cur.first); // store end time of cur movie;
++count;
}
cout << count;
return 0;
}