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(); TreeMap> map = new TreeMap<>(); for (int i = 0; i < m; i++) { int x = sc.nextInt(); int y = sc.nextInt(); if (!map.containsKey(x)) { map.put(x, new HashSet<>()); } map.get(x).add(y); } HashSet enable = new HashSet<>(); enable.add(n); for (HashSet exist : map.values()) { HashSet next = new HashSet<>(); for (int x : exist) { if (enable.contains(x - 1) || enable.contains(x + 1)) { next.add(x); } } for (int x : exist) { enable.remove(x); } enable.addAll(next); } System.out.println(enable.size()); } } 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 next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }