n,m = map(int,input().split())
sc = [ list(map(int,input().split())) for _ in range(m) ]

a = [-1]*n

for i in range(m):
    if a[sc[i][0]-1] == -1:
        a[sc[i][0]-1] = sc[i][1]
    else:
        if a[sc[i][0]-1] == sc[i][1]:
            pass
        else:
            print(-1)
            exit()

if n==1:
    if a[0]==-1:
        print(0)
    else:
        print(a[0])
elif n==2:
    if a[0]==-1 and a[1]!=-1:
        print(10)
    elif a[0]==0:
        print(-1)
    else:
        print("".join(list(map(str,a))))
elif n==3:
    if a[0]==0:
        print(-1)
    elif a[0]==-1:
        a[0]=1
        if a[1]==-1:
            a[1]=0
        if a[2]==-1:
            a[2]=0
        print("".join(list(map(str,a))))
    else:
        if a[1]==-1:
            a[1]=0
        if a[2]==-1:
            a[2]=0
        print("".join(list(map(str,a))))