program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,m,i,x,y,ans
    integer(int32), allocatable:: ball_num(:)
    logical,allocatable:: possible(:)

    
    read*, n,m
    allocate(ball_num(n), source=1)
    allocate(possible(n))
    possible(1) = .true.; possible(2:) = .false.

    do i=1,m
        read*, x,y
        ball_num(x)=ball_num(x)-1
        ball_num(y)=ball_num(y)+1
        if (possible(x)) possible(y)=.true.
        if (ball_num(x) == 0) possible(x) = .false.
    end do

    ans=0
    do i=1,n
        if(possible(i)) ans=ans+1
    end do

    print'(i0)', ans
end program name