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

m.times.each do
    v,vv=gets.split.map(&:to_i)
    check<<v
    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 && all[1]==0
    all.shift
    all.shift
elsif all[0]==0
all.shift
end
if n!=all.length
    p -1
    exit
end

check.uniq!
non_check=[1,2,3]-check
if non_check!=nil
for i in 0..non_check.length-1
    while all[non_check[i]-1]>0
        all[non_check[i]-1]-=1
    end
    
end
end
puts all.join("")