n, m = gets.split.map(&:to_i)
s, c = m.times.map { gets.split.map(&:to_i) }.transpose

nums = Array.new(n + 1, 0)

m.times do |i|
  if nums[s[i]] != 0 && (nums[s[i]] != c[i] || s[i] == 1 && c[i] == 0)
    puts -1
    exit 0
  end

  nums[s[i]] = c[i]
end

if n >= 2 && nums[1] == 0
  puts [1, *nums[2..n]].join('')
else
  puts nums[1..n].join('')
end