let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let count = Array.make (n + 1) 0 in
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d\n" @@ fun l r ->
      count.(l - 1) <- count.(l - 1) + 1;
      count.(r) <- count.(r) - 1;
  done;
  for i = 1 to n do
    count.(i) <- count.(i - 1) + count.(i)
  done;
  Printf.printf "%d\n" @@
  Array.fold_right (fun c -> ( + ) @@ if c < m then 0 else 1) count 0