import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); Area[] areas = new Area[m]; for (int i = 0; i < m; i++) { areas[i] = new Area(sc.nextInt(), sc.nextInt()); } Arrays.sort(areas); TreeSet zeros = new TreeSet<>(); for (Area a : areas) { Integer key = zeros.ceiling(a.left); if (key == null || key > a.right) { zeros.add(a.right); } } System.out.println(n - zeros.size()); } static class Area implements Comparable { int left; int right; public Area(int left, int right) { this.left = left; this.right = right; } public int compareTo(Area another) { return right - another.right; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }