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

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

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

count,cut=0,0



for x,y in box:

    if cut<=x:

        count +=1

        cut=y

        

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

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



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

cnt,cut=0,0



for a,b in AB:

    if cut<=a:

        cnt +=1

        cut=b



print(cnt)
n, m = list(map(int, input().split()))
box = [list(map(int, input().split())) for i in range(m)]
box = sorted(box, key=lambda x: x[1])
count, cut = 0, 0
for x, y in box:
    if cut <= x:
        count += 1
        cut = y
print(count)

n, m = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(m)]
AB = sorted(AB, key=lambda x: x[1])
cnt, cut = 0, 0
for a, b in AB:
    if cut <= a:
        cnt += 1
        cut = b
print(cnt)

-box = [list(map(int, input().split())) for i in range(m)] -box = sorted(box, key=lambda x: x[1]) -count, cut = 0, 0 -for x, y in box: -    if cut <= x: -        count += 1 -        cut = y -print(count) +AB = [tuple(map(int, input().split())) for _ in range(m)] +AB = sorted(AB, key=lambda x: x[1]) +cnt, cut = 0, 0 +for a, b in AB: +    if cut <= a: +        cnt += 1 +        cut = b +print(cnt)