loop do
  n, q = gets.split.map(&:to_i)
  break if n == 0
  count = Hash.new(0)
  n.times do
    gets.split.map(&:to_i)[1..-1].each do |d|
      count[d] += 1
    end
  end
  m = count.values.max
  if m == nil || m < q
    puts 0
  else
    puts count.keys.select {|d| count[d] == m}.min
  end
end
