n,m = gets.split(' ').map(&:to_i)
ary = []
m.times { ary << gets.split(' ').map(&:to_i) }

result = 0
sum = {}

ary.each do |a, b|
  if sum[a].nil?
    sum[a] = b
  else
    result = -1 unless sum[a] == b
  end
end

result = -1 if sum[1] == 0

if result == -1
  puts result
else
  result = ''
  1.upto(n) do |i|
    result << sum[i].to_s unless sum[i].nil?
    result << '0' if sum[i].nil?
  end
  puts result.to_i
end