n, m = gets.split.map(&:to_i)
conds = []
m.times do
  conds.push(gets.split.map(&:to_i))
end

ans = []
possible = true

conds.each do |cond|
  if ans[cond[0]-1] == nil || ans[cond[0]-1] == cond[1]
    ans[cond[0]-1] = cond[1]
    #puts "a"
  else
    puts "-1"
    exit
  end
end

ans.map! do |num|
  if num == nil
    0
  else
    num
  end
end

if ans[0] == 0
  puts "-1"
  exit
end

puts ans.join("")