n,m=map(int,input().split())
l=["0"]*n
f=[0]*n
frag=0
for i in range(m):
    s,c=map(int,input().split())
    if f[s-1]==0 or l[s-1]==str(c):
        l[s-1]=str(c)
        f[s-1]=1
    else:
        frag=1
        break
if frag==1 or l==["0","0","0"]:
    print(-1)
else:
    for j in l:
        if j=="0" and frag==0:
            pass
        else:
            print(j,end="")
            frag=1