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

table = []

ans = 1



for i in range(M):

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

  table.append((a,b))

  

table.sort()

r = N

for a,b in table:

  if r <= a:

    ans += 1

    r = N

  r = min(b,r)

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

table = []

for i in range(M):

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

    a -= 1

    b -= 1

    table.append((a,b))

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

cur_r = table[0][1]

ans = 1

for i in range(1,M):

    l,r = table[i]

    if cur_r <= l:

        ans += 1

        cur_r = r



print(ans)
N, M = list(map(int, input().split()))
table = []
ans = 1
for i in range(M):
    a, b = list(map(int, input().split()))
    table.append((a, b))
table.sort()
r = N
for a, b in table:
    if r <= a:
        ans += 1
        r = N
    r = min(b, r)
print(ans)

N, M = list(map(int, input().split()))
table = []
for i in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    table.append((a, b))
table = sorted(table, key=lambda x: x[1])
cur_r = table[0][1]
ans = 1
for i in range(1, M):
    l, r = table[i]
    if cur_r <= l:
        ans += 1
        cur_r = r
print(ans)

-ans = 1 +    a -= 1 +    b -= 1 -table.sort() -r = N -for a, b in table: -    if r <= a: +table = sorted(table, key=lambda x: x[1]) +cur_r = table[0][1] +ans = 1 +for i in range(1, M): +    l, r = table[i] +    if cur_r <= l: -        r = N -    r = min(b, r) +        cur_r = r