n,m=map(int,input().split())
s=[0]*m
c=[0]*m
t=[]
for i in range(m):
    s[i], c[i]=map(int,input().split())
for i in range(10**n):
    u=str(i)
    try:
        h=0
        for j in range(m):
            if u[s[j]-1] == str(c[j]):
                h+=1
            if j==m-1 and h==m:
                t.append(i)
    except:
       	pass
if len(t)!=0:
    print(min(t))
else:
    print(-1)