n,m=list(map(int,input().split()))
ans=[0 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]!=0 and ans[s]!=c:
        print(-1)
        exit()
    ans[s]=c
ans="".join(map(str,ans))
print(ans)
    
