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(' ') }

  friends, others = [], []

  pairs.each do |pair|
    if pair[0] == '1'
      friends << pair[1] 
    else
      others << pair
    end
  end

  foaf = others.inject([]) do |pairs, pair|
      pairs << pair[1] if friends.include?(pair[0])
      pairs << pair[0] if friends.include?(pair[1])
      pairs
    end

  puts (friends | foaf).uniq.size
end