n,m=list(map(int,input().split()))
ans=[-1 for _ in range(n)]
for i in range(m):
    s,c=list(map(int,input().split()))
    s-=1
    if s==0 and c==0:
        print(-1)
        exit()
    
    if ans[s]!=-1 and ans[s]!=c:
        print(-1)
        exit()
    ans[s]=c
if ans[0]==-1:
    ans[0]=1
ans="".join(map(lambda x:str(max(0,x)),ans))
print(ans)
    