program agc002b
  implicit none
  integer :: n, m, i
  integer,allocatable :: box(:), x(:), y(:), xy(:,:)
  logical,allocatable :: f(:)

  read *, n, m
  allocate(box(n),f(n),xy(2,m))
  box = 1
  f = .false.
  f(1) = .true.
  read *, xy
  x = xy(1,:)
  y = xy(2,:)

  do i = 1,m
     box(x(i)) = box(x(i)) - 1
     box(y(i)) = box(y(i)) + 1
     f(y(i)) = f(y(i)).or.f(x(i))
     if (box(x(i)) == 0) f(x(i)) = .false.
  end do

  print *, count(f)
end program agc002b
