n,m = gets.split(' ').map(&:to_i)
cond = []
m.times {|i| cond << gets.split(' ').map(&:to_i)}
r1 = []
r2 = []
r3 = []
cond.each do |c|
  if c[0] == 1
    r1 << c[1].to_s
    r1 << "-1" if r1.uniq.size > 1
  elsif c[0] == 2
    r2 << c[1].to_s
    r2 << "-1" if r2.uniq.size > 1
  elsif c[0] == 3
    r3 << c[1].to_s
    r3 << "-1" if r3.uniq.size > 1
  end
end
if n == 1
  puts r1.include?("-1") ? "-1" : r1.uniq[0]
elsif n == 2
  if r1.include?("-1") || r2.include?("-1")
    puts "-1"
  elsif r1[0] == "0"
    puts "-1"
  else
    r1 = ["1"] if r1.empty?
    r2 = ["0"] if r2.empty?
    puts r1[0] + r2[0]
  end
elsif n == 3
  if r1.include?("-1") || r2.include?("-1") || r3.include?("-1")
    puts "-1"
  elsif r1[0] == "0"
    puts "-1"
  else
    r1 = ["1"] if r1.empty?
    r2 = ["0"] if r2.empty?
    r3 = ["0"] if r3.empty?
    puts r1[0] + r2[0] + r3[0]
  end
end