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