let rs, cs, xys = Scanf.(Array.(scanf "%d %d" @@ fun n m -> make n 0, make n 1, init m @@ fun _ -> scanf " %d %d" @@ fun a b -> a - 1, b - 1))
let _ = rs.(0) <- 1; Array.(iter (fun (x, y) -> rs.(y) <- max rs.(y) rs.(x); cs.(y) <- cs.(y) + 1; cs.(x) <- cs.(x) - 1; rs.(x) <- min rs.(x) cs.(x)) xys; fold_left (+) 0 rs) |> Printf.printf "%d\n"