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

ab=[0]*m

for i in range(m):

    ab[i] = [int(x) for x in input().split()]

ab.sort()

ans = 1

key = ab[0][1]

for i in range(m):

    if ab[i][0] >= key:

        ans += 1

        key = ab[i][1]

    elif ab[i][1] < key:

        key = ab[i][1]

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



bridge = [None]*m

for i in range(m):

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

  bridge[i] = [b, a]



ans = 0

bridge.sort()



sub = -1

ans = 0

for v in bridge:

  b, a = v[0], v[1]

  if a >= sub:

    sub = b

    ans += 1



print(ans)
n, m = list(map(int, input().split()))
ab = [0] * m
for i in range(m):
    ab[i] = [int(x) for x in input().split()]
ab.sort()
ans = 1
key = ab[0][1]
for i in range(m):
    if ab[i][0] >= key:
        ans += 1
        key = ab[i][1]
    elif ab[i][1] < key:
        key = ab[i][1]
print(ans)

n, m = list(map(int, input().split()))
bridge = [None] * m
for i in range(m):
    a, b = list(map(int, input().split()))
    bridge[i] = [b, a]
ans = 0
bridge.sort()
sub = -1
ans = 0
for v in bridge:
    b, a = v[0], v[1]
    if a >= sub:
        sub = b
        ans += 1
print(ans)

-ab = [0] * m +bridge = [None] * m -    ab[i] = [int(x) for x in input().split()] -ab.sort() -ans = 1 -key = ab[0][1] -for i in range(m): -    if ab[i][0] >= key: +    a, b = list(map(int, input().split())) +    bridge[i] = [b, a] +ans = 0 +bridge.sort() +sub = -1 +ans = 0 +for v in bridge: +    b, a = v[0], v[1] +    if a >= sub: +        sub = b -        key = ab[i][1] -    elif ab[i][1] < key: -        key = ab[i][1]