n,m=[int(x) for x in input().split()]

isA,atob=[0]*n,[n+1]*n

for _ in [0]*m:

    ai,bi=[int(x) for x in input().split()]

    isA[ai-1]=1

    atob[ai-1]=min(atob[ai-1],bi-1)

bstack=n+1

ans=0

for a in range(n):

    if bstack==a:

        ans+=1

        bstack=n+1

    if isA[a]==0:

        continue

    bstack=min(bstack,atob[a])

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

ab=[]

for i in range(m):

    a,b=[int(x) -1 for x in input().split()]

    ab.append((a,b))

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

ans=0

last_bridge=-1

for a,b in ab:

    # print(a,b)

    if last_bridge<a:

        last_bridge=b-1

        ans+=1

print(ans)
n, m = [int(x) for x in input().split()]
isA, atob = [0] * n, [n + 1] * n
for _ in [0] * m:
    ai, bi = [int(x) for x in input().split()]
    isA[ai - 1] = 1
    atob[ai - 1] = min(atob[ai - 1], bi - 1)
bstack = n + 1
ans = 0
for a in range(n):
    if bstack == a:
        ans += 1
        bstack = n + 1
    if isA[a] == 0:
        continue
    bstack = min(bstack, atob[a])
print(ans)

n, m = list(map(int, input().split()))
ab = []
for i in range(m):
    a, b = [int(x) - 1 for x in input().split()]
    ab.append((a, b))
ab = sorted(ab, key=lambda x: x[1])
ans = 0
last_bridge = -1
for a, b in ab:
    # print(a,b)
    if last_bridge < a:
        last_bridge = b - 1
        ans += 1
print(ans)

-n, m = [int(x) for x in input().split()] -isA, atob = [0] * n, [n + 1] * n -for _ in [0] * m: -    ai, bi = [int(x) for x in input().split()] -    isA[ai - 1] = 1 -    atob[ai - 1] = min(atob[ai - 1], bi - 1) -bstack = n + 1 +n, m = list(map(int, input().split())) +ab = [] +for i in range(m): +    a, b = [int(x) - 1 for x in input().split()] +    ab.append((a, b)) +ab = sorted(ab, key=lambda x: x[1]) -for a in range(n): -    if bstack == a: +last_bridge = -1 +for a, b in ab: +    # print(a,b) +    if last_bridge < a: +        last_bridge = b - 1 -        bstack = n + 1 -    if isA[a] == 0: -        continue -    bstack = min(bstack, atob[a])