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

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

ab.sort()



l,r = ab[0][0],ab[0][1]-1



ans = 1



for i in range(1,m):

    l = max(l,ab[i][0])

    r = min(r,ab[i][1]-1)

    if l > r:

        ans += 1

        l,r = ab[i][0],ab[i][1]-1



print(ans)
N,M = list(map(int,input().split()))

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

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



ans = 1

t = AB[0][1]-1



for i in range(M):

    if t < AB[i][0]:

        t = AB[i][1]-1

        ans += 1

print(ans)

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
ab.sort()
l, r = ab[0][0], ab[0][1] - 1
ans = 1
for i in range(1, m):
    l = max(l, ab[i][0])
    r = min(r, ab[i][1] - 1)
    if l > r:
        ans += 1
        l, r = ab[i][0], ab[i][1] - 1
print(ans)

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
AB.sort(key=lambda x: x[1])
ans = 1
t = AB[0][1] - 1
for i in range(M):
    if t < AB[i][0]:
        t = AB[i][1] - 1
        ans += 1
print(ans)

-n, m = list(map(int, input().split())) -ab = [list(map(int, input().split())) for i in range(m)] -ab.sort() -l, r = ab[0][0], ab[0][1] - 1 +N, M = list(map(int, input().split())) +AB = [list(map(int, input().split())) for _ in range(M)] +AB.sort(key=lambda x: x[1]) -for i in range(1, m): -    l = max(l, ab[i][0]) -    r = min(r, ab[i][1] - 1) -    if l > r: +t = AB[0][1] - 1 +for i in range(M): +    if t < AB[i][0]: +        t = AB[i][1] - 1 -        l, r = ab[i][0], ab[i][1] - 1