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



s = []

for i in range(m):

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

    s.append((b,a))

s.sort()



ans = 1

start = s[0][1]

end = s[0][0]

for i in range(1,m):

    temp_start = s[i][1]

    temp_end = s[i][0]

    if temp_start >= end:

        ans += 1

        end = temp_end

    

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

l = []

for i in range(m):

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

    l.append((a,b))



l = sorted(l, reverse=False, key=lambda x: x[1])

ans = 1

tmp = l[0][1]

for i in range(1,len(l)):

    if tmp <= l[i][0]:

        

        tmp = l[i][1]

        ans += 1



print(ans)

    

    
n, m = list(map(int, input().split()))
s = []
for i in range(m):
    a, b = list(map(int, input().split()))
    s.append((b, a))
s.sort()
ans = 1
start = s[0][1]
end = s[0][0]
for i in range(1, m):
    temp_start = s[i][1]
    temp_end = s[i][0]
    if temp_start >= end:
        ans += 1
        end = temp_end
print(ans)

n, m = list(map(int, input().split()))
l = []
for i in range(m):
    a, b = list(map(int, input().split()))
    l.append((a, b))
l = sorted(l, reverse=False, key=lambda x: x[1])
ans = 1
tmp = l[0][1]
for i in range(1, len(l)):
    if tmp <= l[i][0]:
        tmp = l[i][1]
        ans += 1
print(ans)

-s = [] +l = [] -    s.append((b, a)) -s.sort() +    l.append((a, b)) +l = sorted(l, reverse=False, key=lambda x: x[1]) -start = s[0][1] -end = s[0][0] -for i in range(1, m): -    temp_start = s[i][1] -    temp_end = s[i][0] -    if temp_start >= end: +tmp = l[0][1] +for i in range(1, len(l)): +    if tmp <= l[i][0]: +        tmp = l[i][1] -        end = temp_end