require 'set'

N, M = gets.split.map(&:to_i)
guess = [Set.new, Set.new, Set.new]
M.times do
  s, c = gets.split
  guess[s.to_i - 1] << c
end

guess.each do |c|
  if c.length > 1
    puts '-1'
    exit
  end
end

ga = guess[0].first
gb = guess[1].first
gc = guess[2].first

case N
when 3
  ga ||= '1'
when 2
  gb ||= '1'
end

0.upto((10 ** N) - 1) do |i|
  a, b, c = ("%03d" % i).split(//)
  if ga.nil? || ga == a
    if gb.nil? || gb == b
      if gc.nil? || gc == c
        puts i
        exit
      end
    end
  end
end

puts '-1'