program test

integer(8) :: n,m,i,j,k,ans
integer(8) :: a(100000),b(100000),aa(100000)=999999

read(*,*) n,m

do i=1,m
	read(*,*) a(i),b(i)
enddo

do i=1,m
	aa(a(i))=min(aa(a(i)),b(i)-1)
enddo

ans = 0

do i=1,n
 if(aa(i)<999999) then
 	ans = ans + 1
 	do j=i+1,n
 		if(aa(j) <= aa(i)) then
 			aa(j) = 999999
 		endif
 	enddo
 	aa(i) = 999999
 endif
enddo

write(*,*) ans




end program