import java.util.*;
import java.io.*;
public class MovieFestival2 {
setIO();
st = nl();
int N = ni(st), K = ni(st);
Movie[] M = new Movie[N];
for (int i = 0; i < N; i++) {
st = nl();
int s = ni(st), e = ni(st);
M[i] = new Movie(s, e);
}
ms.put(0, K);
int ans = 0;
for (int i = 0; i < N; i++) {
if (ms.floorKey(M[i].s) != null) {
delete(ms.floorKey(M[i].s));
add(M[i].e);
ans++;
}
}
out.println(ans);
f.close();
out.close();
}
static TreeMap
<Integer, Integer
> ms
= new TreeMap
<>();
static void add(int x) {
ms.put(x, ms.getOrDefault(x, 0) + 1);
}
static void delete(int x) {
int c = ms.get(x);
ms.put(x, --c);
if (c == 0)
ms.remove(x);
}
static class Movie implements Comparable<Movie> {
int s, e;
Movie(int s, int e) {
this.s = s;
this.e = e;
}
public int compareTo(Movie o) {
return Integer.
compare(this.
e, o.
e); }
}
return Integer.
parseInt(st.
nextToken()); }
return Integer.
parseInt(f.
readLine()); }
}
int[] A = new int[N];
for (int i = 0; i < N; i++)
A[i] = ni(st);
return A;
}
}
}
static void setIn() {
}
static void setOut() {
}
setIn(s + ".in");
setOut(s + ".out");
}
static void setIO() {
setIn();
setOut();
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5pby4qOwogCnB1YmxpYyBjbGFzcyBNb3ZpZUZlc3RpdmFsMiB7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB0aHJvd3MgSU9FeGNlcHRpb24gewoJCXNldElPKCk7CiAKCQlzdCA9IG5sKCk7CgkJaW50IE4gPSBuaShzdCksIEsgPSBuaShzdCk7CgkJTW92aWVbXSBNID0gbmV3IE1vdmllW05dOwoJCWZvciAoaW50IGkgPSAwOyBpIDwgTjsgaSsrKSB7CgkJCXN0ID0gbmwoKTsKCQkJaW50IHMgPSBuaShzdCksIGUgPSBuaShzdCk7CgkJCU1baV0gPSBuZXcgTW92aWUocywgZSk7CgkJfQoJCUFycmF5cy5zb3J0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