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

marked = Array.new(n, false)
number = Array.new(n, 0)
m.times do |i|
  if marked[s[i] - 1] == false
    number[s[i] - 1] = c[i]
    marked[s[i] - 1] = true
  elsif number[s[i] - 1] != c[i]
    puts -1
    exit
  end
end

if number[0] == 0 && number.length > 0
  puts -1
  exit
end

ans = ''
number.each do |d|
  ans += "#{d}"
end
puts ans
