let n, m = Scanf.scanf "%d %d " (fun x y -> x, y)

let rec rev_read_ints accu = function
  | 0 -> accu
  | k -> rev_read_ints ((Scanf.scanf "%d %d\n" (fun x y -> x-1, y-1)) :: accu) (k-1)

let xy = List.rev (rev_read_ints [] m)

let possible = Array.make n false
let () = possible.(0) <- true

let numbers = Array.make n 1

let rec solve = function
  | [] -> ()
  | (x, y) :: tl -> if possible.(x) then begin possible.(y) <- true; if numbers.(x) = 1 then possible.(x) <- false end;
    numbers.(x) <- numbers.(x) - 1; numbers.(y) <- numbers.(y) + 1; solve tl

let () = solve xy; print_int (Array.fold_left (fun x y -> x + (if y then 1 else 0)) 0 possible)