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

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

M.sort(key=lambda X: X[1])

end,ans=0,0



for i in range(m):

  if M[i][0] >= end:

    ans += 1

    end=M[i][1]

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

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

M.sort(key=lambda X: X[1])

end,ans=0,0



for a,b in M:

  if a >= end:

    ans += 1

    end=b

print(ans)
n, m = list(map(int, input().split()))
M = [list(map(int, input().split())) for _ in range(m)]
M.sort(key=lambda X: X[1])
end, ans = 0, 0
for i in range(m):
    if M[i][0] >= end:
        ans += 1
        end = M[i][1]
print(ans)

n, m = list(map(int, input().split()))
M = [list(map(int, input().split())) for _ in range(m)]
M.sort(key=lambda X: X[1])
end, ans = 0, 0
for a, b in M:
    if a >= end:
        ans += 1
        end = b
print(ans)

-for i in range(m): -    if M[i][0] >= end: +for a, b in M: +    if a >= end: -        end = M[i][1] +        end = b