n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
p=m
m=[-1 for i in range(n)]

b=0
for i in range(p):
    if m[l[i][0]-1]==-1:
        m[l[i][0]-1]=l[i][1]
    else:
        if m[l[i][0]-1]!=l[i][1]:
            b=1
            break

if b==1 or m[0]==0:
    print(-1)
else:
    k=0
    for i in range(n):
        if m[i]>-1:
            print(m[i],end="")
        if m[i]==-1 and i!=0:
            print(0,end="")
        