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

a = []

for i in range(M):

    a.append(list(map(int,input().split())))

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

bridges = []



for i in range(M): 

    flag = 1

    for bridge in bridges:

        if a[i][0] <= bridge and bridge < a[i][1]:

            flag = 0

            break 

    if flag:	bridges.append(a[i][1] - 1)   

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

a = []

for i in range(M):

    a.append(list(map(int,input().split())))

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

left = -1

ans = 0

for i in range(M):

    if left < a[i][0]:

      left = a[i][1] - 1

      ans += 1

print(ans)
N, M = list(map(int, input().split()))
a = []
for i in range(M):
    a.append(list(map(int, input().split())))
a = sorted(a, key=lambda x: x[1])
bridges = []
for i in range(M):
    flag = 1
    for bridge in bridges:
        if a[i][0] <= bridge and bridge < a[i][1]:
            flag = 0
            break
    if flag:
        bridges.append(a[i][1] - 1)
print((len(bridges)))

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

-bridges = [] +left = -1 +ans = 0 -    flag = 1 -    for bridge in bridges: -        if a[i][0] <= bridge and bridge < a[i][1]: -            flag = 0 -            break -    if flag: -        bridges.append(a[i][1] - 1) -print((len(bridges))) +    if left < a[i][0]: +        left = a[i][1] - 1 +        ans += 1 +print(ans)