
require "set"
N,M=gets.split.map{|i| i.to_i}

A=(1..N).map{|i| Set.new }

for i in 1..M
    s,c=gets.split.map{|i| i.to_i}
    A[s-1].add(c)
end

str=""

v=A[0].to_a
if v.length>=2 
    puts "-1"
    exit
end
if v.length ==1 and v[0]!=0
   str << v[0].to_s
elsif v.length==0
    str<<1.to_s
else
    puts -1
    exit
end



for i in A.slice(1..N)
    v=i.to_a
    if v.length>=2
        puts -1
        exit
    end
    if v.length==0
        str << "0"
    else
        str << (v[0].to_s)
    end
end
puts str

