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



ans = 0

ba = [[0 for _ in range(2)] for _ in range(m)]



for i in range(m):

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

    ba[i][0] = b

    ba[i][1] = a



ba.sort()



br = 0

for b,a in ba:

    #if bridge[(a-1):] != 0:

    if not (a < br < b):

        #bridge[b-2] = 0

        br = b - 0.5

        ans += 1



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

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

ab.sort()

ans = 1

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



for a,b in ab[1:]:

    if a < r:

        l = max(l,a)

        r = min(r,b)

    else:

        ans += 1

        l = a

        r = b 



print(ans)
n, m = list(map(int, input().split()))
ans = 0
ba = [[0 for _ in range(2)] for _ in range(m)]
for i in range(m):
    a, b = list(map(int, input().split()))
    ba[i][0] = b
    ba[i][1] = a
ba.sort()
br = 0
for b, a in ba:
    # if bridge[(a-1):] != 0:
    if not (a < br < b):
        # bridge[b-2] = 0
        br = b - 0.5
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(M)]
ab.sort()
ans = 1
l, r = ab[0][0], ab[0][1]
for a, b in ab[1:]:
    if a < r:
        l = max(l, a)
        r = min(r, b)
    else:
        ans += 1
        l = a
        r = b
print(ans)

-n, m = list(map(int, input().split())) -ans = 0 -ba = [[0 for _ in range(2)] for _ in range(m)] -for i in range(m): -    a, b = list(map(int, input().split())) -    ba[i][0] = b -    ba[i][1] = a -ba.sort() -br = 0 -for b, a in ba: -    # if bridge[(a-1):] != 0: -    if not (a < br < b): -        # bridge[b-2] = 0 -        br = b - 0.5 +N, M = list(map(int, input().split())) +ab = [tuple(map(int, input().split())) for _ in range(M)] +ab.sort() +ans = 1 +l, r = ab[0][0], ab[0][1] +for a, b in ab[1:]: +    if a < r: +        l = max(l, a) +        r = min(r, b) +    else: +        l = a +        r = b