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



cut  = []

for _ in range(m):

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

  cut.append((a,b))



cut.sort()



b_min = cut[0][1]

count = 0



for a,b in cut[1:]:

  if b_min > b:

    b_min = b

    continue

  if b_min <= a:

    count += 1

    b_min = b



print((count+1))



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

cut = []

for _ in range(m):

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

  cut.append((a,b))

cut.sort(key = lambda x:x[1])



ex_b  = cut[0][1]

count = 0

for a,b in cut[1:]:

  if a >= ex_b:

    count += 1

    ex_b = b

print((count+1))



n, m = list(map(int, input().split()))
cut = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    cut.append((a, b))
cut.sort()
b_min = cut[0][1]
count = 0
for a, b in cut[1:]:
    if b_min > b:
        b_min = b
        continue
    if b_min <= a:
        count += 1
        b_min = b
print((count + 1))

n, m = list(map(int, input().split()))
cut = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    cut.append((a, b))
cut.sort(key=lambda x: x[1])
ex_b = cut[0][1]
count = 0
for a, b in cut[1:]:
    if a >= ex_b:
        count += 1
        ex_b = b
print((count + 1))

-cut.sort() -b_min = cut[0][1] +cut.sort(key=lambda x: x[1]) +ex_b = cut[0][1] -    if b_min > b: -        b_min = b -        continue -    if b_min <= a: +    if a >= ex_b: -        b_min = b +        ex_b = b