n, m = list(map(int, input().split()))

info = []

for _ in range(m):

    a, b = list(map(int, input().split()))

    a, b = a-1, b-1

    info.append([a, b])

info.sort()

tmp = []

for i, j in enumerate(info):

    if i == 0:

        tmp.append(j[1])

    elif j[0] > tmp[-1]-1:

        tmp.append(j[1])

    else:

        if j[1] < tmp[-1]:

            tmp[-1] = j[1]

print((len(tmp)))
n, m = list(map(int, input().split()))

line = [list(map(int, input().split())) for _ in range(m)]

line.sort(key=lambda x: x[1])



ans = 1

now = line[0][1]

for s, g in line[1:]:

    if s >= now:

        ans += 1

        now = g

print(ans)

n, m = list(map(int, input().split()))
info = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    info.append([a, b])
info.sort()
tmp = []
for i, j in enumerate(info):
    if i == 0:
        tmp.append(j[1])
    elif j[0] > tmp[-1] - 1:
        tmp.append(j[1])
    else:
        if j[1] < tmp[-1]:
            tmp[-1] = j[1]
print((len(tmp)))

n, m = list(map(int, input().split()))
line = [list(map(int, input().split())) for _ in range(m)]
line.sort(key=lambda x: x[1])
ans = 1
now = line[0][1]
for s, g in line[1:]:
    if s >= now:
        ans += 1
        now = g
print(ans)

-info = [] -for _ in range(m): -    a, b = list(map(int, input().split())) -    a, b = a - 1, b - 1 -    info.append([a, b]) -info.sort() -tmp = [] -for i, j in enumerate(info): -    if i == 0: -        tmp.append(j[1]) -    elif j[0] > tmp[-1] - 1: -        tmp.append(j[1]) -    else: -        if j[1] < tmp[-1]: -            tmp[-1] = j[1] -print((len(tmp))) +line = [list(map(int, input().split())) for _ in range(m)] +line.sort(key=lambda x: x[1]) +ans = 1 +now = line[0][1] +for s, g in line[1:]: +    if s >= now: +        ans += 1 +        now = g +print(ans)