require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,m = gets.chomp.split.map(&:to_i)

a = Array.new(n)

m.times do
  s, c = gets.chomp.split.map(&:to_i)

  if !a[s-1].nil? && a[s-1] != c
    puts -1
    exit
  end

  a[s-1] = c
end

0.upto(999) do |i|
  s = i.to_s.split(//).map(&:to_i)
  s.unshift nil if s.size < 3
  s.unshift nil if s.size < 3
  flg = true
  n.times do |j|
    next if a[j].nil?
    if a[j] != s[j]
      flg = false
      break
    end
  end
  if flg
    puts i
    exit
  end
end

puts -1