n, m = gets.split(" ").map(&:to_i)
ary = []
m.times do
  ary << gets.split(" ").map(&:to_i)
end

if ary.include?([1, 0])
  puts -1
  exit
end

l = n.to_s.size
span = [l*10..((l+1)*10-1)].to_a

# 0でOKなとき
if n == 1 && ary[0] == [1, 0]
  puts 0
  exit
end

ary = ary.sort
(m-1).times do |i|
  if ary[i][0] == ary[i+1][0] && ary[i][1] != ary[i+1][1]
    puts -1
    exit
  end
end

num = "0"*n

m.times do |i|
  num[(ary[i][0]-1)] = "#{ary[i][1]}"
end

if num[0] != "0"
  puts num.to_i
else
  num[0] = "1"
  puts num.to_i
end
