loop do
  n = gets.chomp.to_i
  row_count = gets.chomp.to_i

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

  pairs = row_count.times.map { gets.chomp.split(' ').map(&:to_i) }

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

  puts (friends | foaf).uniq.delete_if { |i| i == 1 }.size
end