import sys
n,m=map(int,input().split())
l=[0,0,0]
a=[0,0,0]
for i in range(m):
    s,c=map(int,input().split())
    if a[s-1]==1:
        if l[s-1]==c:
            pass
        else:
            print(-1)
            sys.exit()
    else:
        l[s-1]=c
        a[s-1]=1
if n==1:
    pass
else:
    if l[0]==0:
        if a[0]==0:
            l[0]=1
if n!=1 and l[0]==0:
    print(-1)
    sys.exit()
a=""
for i in range(3):
    a+=str(l[i])
print(int(a))