n,m=map(int,input().split())
ans=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]!=-1 and ans[s-1]!=c:
        print(-1)
        exit()
    ans[s-1]=c
if ans[0]==-1:
    ans[0]=1
elif ans[0]==0:
    print(-1)
    exit()
x=0
for i in range(n):
    x*=10
    if ans[i]!=-1:
        x+=ans[i]

print(x if x!=0 else -1)
