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



bridges = []

for i in range(M):

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



intervals = sorted(bridges, key=lambda x: (x[1], x[0]))



#print(bridges)

count=1

done=[intervals[0]]



for interval in intervals:

	#print(interval)

	if not interval[0] < done[-1][1]:

		count += 1

		done.append(interval)	

#print(done)

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



bridges = []

for i in range(M):

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



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



#print(bridges)

count=1

done=[intervals[0]]



for interval in intervals:

	#print(interval)

    # we cut the last bridage of last processed interval

	if not interval[0] < done[-1][1]:

		count += 1

		done.append(interval)	

#print(done)

print(count) 
N, M = list(map(int, input().split()))
bridges = []
for i in range(M):
    bridges.append(list(map(int, input().split())))
intervals = sorted(bridges, key=lambda x: (x[1], x[0]))
# print(bridges)
count = 1
done = [intervals[0]]
for interval in intervals:
    # print(interval)
    if not interval[0] < done[-1][1]:
        count += 1
        done.append(interval)
# print(done)
print(count)

N, M = list(map(int, input().split()))
bridges = []
for i in range(M):
    bridges.append(list(map(int, input().split())))
intervals = sorted(bridges, key=lambda x: x[1])
# print(bridges)
count = 1
done = [intervals[0]]
for interval in intervals:
    # print(interval)
    # we cut the last bridage of last processed interval
    if not interval[0] < done[-1][1]:
        count += 1
        done.append(interval)
# print(done)
print(count)

-intervals = sorted(bridges, key=lambda x: (x[1], x[0])) +intervals = sorted(bridges, key=lambda x: x[1]) +    # we cut the last bridage of last processed interval