n,m=map(int,input().split())
z={}
f=1
maxs=0
ii=1
ss=1
if m==0 and n==1:
    print(0)
    exit()
elif m==0 and n==2:
  	print(10)
    exit()
elif m==0 and n==3:
  	print(100)
    exit()
for i in range(m):
    s,c=map(int,input().split())
    if n!=1 and s==1 and c==0:
        print(-1)
        exit()
    if ii==1:
        ii=c
    elif ii!=1:
        ii=min(c,ii)
    if s not in z:
        z[s]=ii
    elif z[s]==c:
        continue
    else:
        f=0
        continue
sorted(z.items(),key=lambda x:x[1])
if not f:
    print(-1)
    exit()
for i in range(1,n+1):
    if i in z:
        print(z[i],end="")
    elif i!=1:
        print(0,end="")
    else:
        print(1,end="")