import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = Integer.parseInt(sa[1]); Obj[] arr = new Obj[m]; for (int i = 0; i < m; i++) { sa = br.readLine().split(" "); Obj o = new Obj(); o.l = Integer.parseInt(sa[0]); o.r = Integer.parseInt(sa[1]); arr[i] = o; } br.close(); Arrays.sort(arr, (o1, o2) -> o1.r - o2.r); int cnt = 0; int x = 0; for (int i = 0; i < m; i++) { Obj o = arr[i]; if (x < o.l) { x = o.r; cnt++; } } System.out.println(n - cnt); } static class Obj { int l, r; } }