n,m=map(int,input().split())
l=[0 for i in range(0,3)]

flag=0
f=0

if m>0:
    for j in range(0,m):
        s,c=map(int,input().split())
        if l[s-1]==0:
            l[s-1]=c
        else:
            if l[s-1]!=c:
                flag=1
                break
        if s==1 and c==0:
            flag=1
            break

if flag==1:
    print(-1)

if l[0]==0:
    for k in range(1,3):
        print(l[k],end="")
        f=1
if l[1]!=0:
    if f==0:
        for k in range(0,3):
            print(l[k],end="")
            f=1
if l[1]==0:
    if f==0:
        print(l[2],end="")
