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

ab=[]

for m in range(M):

  [a,b]=[int(i) for i in input().split()]

  ab.append([a,b])

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

count=[]

count.append(ab[0][1]-1)

for i in range(1,M):

  if ab[i][0]<=count[-1]<ab[i][1]:

    pass

  elif ab[i][0]<=count[-1] and ab[i][1]-1==count[-1]:

    count.remove(count[-1])

    count.append(ab[i][1]-1)

  else:

    count.append(ab[i][1]-1)

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

B=[]

for _ in range(m):

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

  B.append([a-1,b-1])

  

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

ans=m

for i in range(1,m):

  if B[i][0]<B[i-1][1]:

    ans-=1

    B[i][1]=B[i-1][1]

    

print(ans)
N, M = list(map(int, input().split()))
ab = []
for m in range(M):
    [a, b] = [int(i) for i in input().split()]
    ab.append([a, b])
ab.sort(key=lambda x: x[1])
count = []
count.append(ab[0][1] - 1)
for i in range(1, M):
    if ab[i][0] <= count[-1] < ab[i][1]:
        pass
    elif ab[i][0] <= count[-1] and ab[i][1] - 1 == count[-1]:
        count.remove(count[-1])
        count.append(ab[i][1] - 1)
    else:
        count.append(ab[i][1] - 1)
print((len(count)))

n, m = list(map(int, input().split()))
B = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    B.append([a - 1, b - 1])
B = sorted(B, key=lambda x: x[1])
ans = m
for i in range(1, m):
    if B[i][0] < B[i - 1][1]:
        ans -= 1
        B[i][1] = B[i - 1][1]
print(ans)

-N, M = list(map(int, input().split())) -ab = [] -for m in range(M): -    [a, b] = [int(i) for i in input().split()] -    ab.append([a, b]) -ab.sort(key=lambda x: x[1]) -count = [] -count.append(ab[0][1] - 1) -for i in range(1, M): -    if ab[i][0] <= count[-1] < ab[i][1]: -        pass -    elif ab[i][0] <= count[-1] and ab[i][1] - 1 == count[-1]: -        count.remove(count[-1]) -        count.append(ab[i][1] - 1) -    else: -        count.append(ab[i][1] - 1) -print((len(count))) +n, m = list(map(int, input().split())) +B = [] +for _ in range(m): +    a, b = list(map(int, input().split())) +    B.append([a - 1, b - 1]) +B = sorted(B, key=lambda x: x[1]) +ans = m +for i in range(1, m): +    if B[i][0] < B[i - 1][1]: +        ans -= 1 +        B[i][1] = B[i - 1][1] +print(ans)