N, M = gets.split.map(&:to_i)
str = "*" * N

M.times do |i|
  s,c = gets.split.map(&:to_i)
  if (str[s-1] != "*") && (str[s-1] != c.to_s)
    puts "-1"
    exit
  else
    str[s-1] = c.to_s
  end
end
str = str.gsub(/\*/, '0')
if str[0] == "*" && N != 1
  str[0] == "1"
end

val = str.to_i
ret = val.to_s
if ret.length != N
  puts "-1"
else
  puts ret
end
