while true
  n, q = gets.chomp.split(" ").map(&:to_i)
  break if n == 0 && q == 0
  a = Array.new(101, 0)
  n.times do
    m, *d = gets.chomp.split(" ").map(&:to_i)
    m.times do |i|
      a[d[i]] += 1
    end
  end
  if a.max >= q then
    puts a.index(a.max)
  else
    puts 0
  end
end