n, m = gets.chomp.split(" ").map(&:to_i)
arr = Array.new(n){[]}
#p arr
count = 0
(0...m).each do 
    a, c = gets.chomp.split(" ")
    a = a.to_i
    if arr[a-1] == []
        arr[a-1] << c
    elsif arr[a-1] != c
        count += 1
    end
end
(0...n).each do |i|
    if arr[i] == []
        arr[i] << "0"
    end
end
ar = []
arr.each do |o|
     ar << o[0]
end
#p ar[0]
#p arr
aaa = ar.count("0")
if aaa == n || ar[0] == "0" || count >= 1
    print "-1"
else
    ar.each do |w|
        print w
    end
end
print "\n"