*D, = open(0)

n, m = list(map(int, D[0].split()))

edges = [list(map(int, it.split())) for it in D[1:]]

edges = sorted(edges, key=lambda x:x[1])



cnt = 0

while len(edges)>0:

    cnt += 1

    new_edges = []

    bridge = edges[0][1]

    for it in edges:

        if it[0]>=bridge:

            new_edges.append(it)

            

    edges = new_edges

print(cnt)
*D, = open(0)

n, m = list(map(int, D[0].split()))

edges = [list(map(int, it.split())) for it in D[1:]]

edges = sorted(edges, key=lambda x:x[1])



bridge = edges[0][1]

cnt = 1

for a, b in edges[1:]:

    if bridge <= a:

        bridge = b

        cnt += 1

print(cnt)
(*D,) = open(0)
n, m = list(map(int, D[0].split()))
edges = [list(map(int, it.split())) for it in D[1:]]
edges = sorted(edges, key=lambda x: x[1])
cnt = 0
while len(edges) > 0:
    cnt += 1
    new_edges = []
    bridge = edges[0][1]
    for it in edges:
        if it[0] >= bridge:
            new_edges.append(it)
    edges = new_edges
print(cnt)

(*D,) = open(0)
n, m = list(map(int, D[0].split()))
edges = [list(map(int, it.split())) for it in D[1:]]
edges = sorted(edges, key=lambda x: x[1])
bridge = edges[0][1]
cnt = 1
for a, b in edges[1:]:
    if bridge <= a:
        bridge = b
        cnt += 1
print(cnt)

-cnt = 0 -while len(edges) > 0: -    cnt += 1 -    new_edges = [] -    bridge = edges[0][1] -    for it in edges: -        if it[0] >= bridge: -            new_edges.append(it) -    edges = new_edges +bridge = edges[0][1] +cnt = 1 +for a, b in edges[1:]: +    if bridge <= a: +        bridge = b +        cnt += 1