n,m = gets.split.map(&:to_i)
s = []
c = []
m.times do
  line = gets.chop.split.map(&:to_i)
  s << line.shift
  c << line
end
ans = [0,0,0]
a = s.uniq.count
b = c.uniq.count
if a == b
  m.times do |e|
    if s[e] == 1
      ans[0] = c[e]
    elsif s[e] == 2
      ans[1] = c[e]
    elsif s[e] == 3
      ans[2] = c[e]
    end
  end
  if ans[0] == 0
    ans.delete_at(0)
  elsif ans[0]==0 && ans[1] == 0
    ans.delete(0)
  end
puts ans*""
elsif a!=b
  puts "-1"
end
