n,m = gets.split.map(&:to_i) x = n.times.map{[]} at = 0 m.times{ a,b=gets.split.map(&:to_i) at=a x[a]<0}.size con = 0 q = [at] ch = Array.new(n, false) while q.size>0 now = q.shift ch[now] = true x[now].each{|ne| next if ch[now] q<