import numpy as np



def main():

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

  ab=[]

  for _ in range(M):

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

    ab.append([b,a])

  ab.sort()

  tmp=0

  count = 0

  for i in range(M):

    if ab[i][1] >= tmp:

      tmp = ab[i][0]

      count += 1

  print(count)



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

ts = []

for i in range(M):

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

    ts.append([b,a])

ts.sort()

tmp = 0

count = 0

for i in range(M):

    if ts[i][1]>=tmp:

        tmp = ts[i][0]

        count += 1

print(count)
import numpy as np


def main():
    N, M = list(map(int, input().split()))
    ab = []
    for _ in range(M):
        a, b = list(map(int, input().split()))
        ab.append([b, a])
    ab.sort()
    tmp = 0
    count = 0
    for i in range(M):
        if ab[i][1] >= tmp:
            tmp = ab[i][0]
            count += 1
    print(count)


main()

N, M = list(map(int, input().split()))
ts = []
for i in range(M):
    a, b = list(map(int, input().split()))
    ts.append([b, a])
ts.sort()
tmp = 0
count = 0
for i in range(M):
    if ts[i][1] >= tmp:
        tmp = ts[i][0]
        count += 1
print(count)

-import numpy as np - - -def main(): -    N, M = list(map(int, input().split())) -    ab = [] -    for _ in range(M): -        a, b = list(map(int, input().split())) -        ab.append([b, a]) -    ab.sort() -    tmp = 0 -    count = 0 -    for i in range(M): -        if ab[i][1] >= tmp: -            tmp = ab[i][0] -            count += 1 -    print(count) - - -main() +N, M = list(map(int, input().split())) +ts = [] +for i in range(M): +    a, b = list(map(int, input().split())) +    ts.append([b, a]) +ts.sort() +tmp = 0 +count = 0 +for i in range(M): +    if ts[i][1] >= tmp: +        tmp = ts[i][0] +        count += 1 +print(count)