n,m = map(int,input().split())
s=[0]*m
c=[0]*m
ans=[]
judge=False
for i in range(m):
    s[i],c[i]=map(int,input().split())
for j in range(10**n):
    j=str(j)
    for l in range(m):
        if int(j[s[l]-1])==c[l]:
            pass
        else:
            break
    else:
        ans.append(int(j))
        judge=True
if judge:
    print(min(ans))
else:
    print('-1')