n,m=gets.split.map(&:to_i)
all=Array.new(n){0}

m.times.each do
    v,vv=gets.split.map(&:to_i)
    if all[v-1]==0
        all[v-1]=vv
    elsif all[v-1]==vv
    next
    elsif all[v-1]!=vv && all[v-1]!=0
    p -1
    exit
    end
end

if all[0]==0
p -1
else
puts all.join("")
end