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

ab=[list(map(int,input().split()))for _ in range(m)]

ab.sort()

l,r=ab[0]

ans=1

for i,j in ab[1:]:

  if j<=l or r<=i:

    ans+=1

    l,r=i,j

  l=max(l,i)

  r=min(r,j)

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

ab=[list(map(int,input().split()))for _ in range(m)]

ab.sort()

l,r=ab[0]

ans=1

for a,b in ab[1:]:

  if r<=a:

    ans+=1

    l,r=a,b

  else:

    l=max(l,a)

    r=min(r,b)

print(ans)
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
ab.sort()
l, r = ab[0]
ans = 1
for i, j in ab[1:]:
    if j <= l or r <= i:
        ans += 1
        l, r = i, j
    l = max(l, i)
    r = min(r, j)
print(ans)

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
ab.sort()
l, r = ab[0]
ans = 1
for a, b in ab[1:]:
    if r <= a:
        ans += 1
        l, r = a, b
    else:
        l = max(l, a)
        r = min(r, b)
print(ans)

-for i, j in ab[1:]: -    if j <= l or r <= i: +for a, b in ab[1:]: +    if r <= a: -        l, r = i, j -    l = max(l, i) -    r = min(r, j) +        l, r = a, b +    else: +        l = max(l, a) +        r = min(r, b)