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

l=[]

l=sorted([list(map(int,input().split())) for i in range(m)],key=lambda x:x[1])

ans=1

now=l[0][1]-1



for x,y in l[1:]:

    if x<=now<=y-1:continue

    ans+=1

    now=y-1

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

ans=0

head=1

from operator import itemgetter as it

for x,y in sorted([list(map(int,input().split()))for i in range(m)],reverse=0,key=lambda x:(it(1)(x)*(n+1)*10-it(0)(x))):

    if not(x<head <=y):

        head=y

        ans+=1

print(ans)
n, m = list(map(int, input().split()))
l = []
l = sorted([list(map(int, input().split())) for i in range(m)], key=lambda x: x[1])
ans = 1
now = l[0][1] - 1
for x, y in l[1:]:
    if x <= now <= y - 1:
        continue
    ans += 1
    now = y - 1
print(ans)

n, m = list(map(int, input().split()))
ans = 0
head = 1
from operator import itemgetter as it

for x, y in sorted(
    [list(map(int, input().split())) for i in range(m)],
    reverse=0,
    key=lambda x: (it(1)(x) * (n + 1) * 10 - it(0)(x)),
):
    if not (x < head <= y):
        head = y
        ans += 1
print(ans)

-l = [] -l = sorted([list(map(int, input().split())) for i in range(m)], key=lambda x: x[1]) -ans = 1 -now = l[0][1] - 1 -for x, y in l[1:]: -    if x <= now <= y - 1: -        continue -    ans += 1 -    now = y - 1 +ans = 0 +head = 1 +from operator import itemgetter as it + +for x, y in sorted( +    [list(map(int, input().split())) for i in range(m)], +    reverse=0, +    key=lambda x: (it(1)(x) * (n + 1) * 10 - it(0)(x)), +): +    if not (x < head <= y): +        head = y +        ans += 1