# frozen_string_literal: true

n, m = gets.split.map(&:to_i)
s = Hash.new(nil)
t = Hash.new(0)
an = 0
m.times do
  a, b = gets.split.map(&:to_i)
  an = 1 if t[a] != 0 && s[a] != b
  s[a] =  b
  t[a] += 1
end
an = 1 if s[1] == 0 && n != 1
s[1] = 1 if s[1].nil? && (!s[2].nil? || !s[3].nil?)

s[2] = 0 if n > 1 && s[2].nil?
s[3] = 0 if n > 1 && s[3].nil?

puts s[1] if n == 1 && an != 1

if n > 1 && an != 1
  (1..n).each do |i|
    print s[i]
  end
  puts
end
puts -1 if an == 1
