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

g = guess.map {|c|
  c.uniq!
  if c.length == 0
    '0'
  elsif c.length == 1
    c.first.to_s
  else
    puts '-1'
    exit
  end
}

gg = g.join.to_i

if gg.to_s.length == N
  puts gg
elsif gg.to_s.length > N
  puts '-1'
elsif gg == 0
  puts N == 1 ? 0 : '-1'
else
  case N
  when 3
    puts gg + 100
  when 2
    puts gg + 10
  end
end
