Scanf.scanf "%d %d" (fun n m ->
    let balls = Array.make n 1 in
    let red   = Array.make n false in
    red.(0) <- true;
    for i = 1 to m do
        Scanf.scanf " %d %d" (fun x y ->
            let x = x - 1 in let y = y - 1 in
            if red.(x) then (
                if balls.(x) = 1 then red.(x) <- false;
                red.(y) <- true
            );
            balls.(x) <- balls.(x) - 1;
            balls.(y) <- balls.(y) + 1;
        )
    done;
    Array.fold_left (fun acc v -> if v then acc + 1 else acc) 0 red |> Printf.printf "%d\n"
)