#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,m=map(int,input().split())\n"
"s=[list(map(int,input().split()))for _ in range(m)]\n"
"s.sort(key=lambda x:x[0])\n"
"c=a=0\n"
"while c<m:\n"
"    i=1\n"
"    t=s[0][1]\n"
"    while i<len(s)and s[i][0]<t:\n"
"        t=min(t,s[i][1])\n"
"        i+=1\n"
"    c+=i\n"
"    s=s[i:]\n"
"    a+=1\n"
"print(a)\n"
"\"";
  system(s);
  return 0;
}            