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