loop do
  n = gets
  row_count = gets

  break if n == '0' && row_count == '0'

  pairs = []

  pairs << gets.split(' ') while row_count != 0

  friends = pairs.select { |pair| pair[0] == '1' }.map(&:last)
  foaf = pairs.select { |pair|
      friends.include?(pair[0]) || friends.include?(pair[1])
    }.flatten

  puts (friends || foaf).uniq.size
end