import sys
n,m=map(int,input().split())
c=[]
s=[]
keta=[-1,-1,-1]
ans=-1
for i in range(m):
    x,y=map(int,input().split())
    if(keta[x-1]==-1 or keta[x-1]==y):
        keta[x-1]=y
    else:
        print(ans)
        sys.exit()
    if x==1 and y==0:
        print(ans)
        sys.exit()
if keta[0]==-1:
    keta[0]=1
if keta[1]==-1:
    keta[1]=0
if keta[2]==-1:
    keta[2]=0

a=[]
for i in keta:
    a.append(str(i))
print(''.join(a))
