# https://atcoder.jp/contests/abc157/tasks/abc157_c


N, M = gets.split.map(&:to_i)
ss = Array.new(M)
cs = Array.new(M)
M.times do |i|
  ss[i], cs[i] = gets.split.map(&:to_i)
end

str = Array.new(N, nil)

ans = -1

noCheck = false

M.times do |i|
  if ss[i] == 1 && cs[i] == 0 then
    noCheck = true
    break
  elsif str[ss[i] - 1] == nil then
    str[ss[i] - 1] = cs[i]
  elsif str[ss[i] - 1] != cs[i]
    noCheck = true
    break
  end
end

N.times do |i|
  str[i] = 0 if str[i] == nil
end

unless noCheck then
  ans = str.join.to_i
  if ans.to_s.length == N then
    puts ans > 0 ? ans : "-1"
  else
    puts "-1"
  end
else
  puts "-1"
end
