import sys
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 or ans[s-1]==c:
        ans[s-1]=c
    else:
        print(-1)
        sys.exit()
if N!=1 and ans[0]==0:
    print(-1)
else:
    l=[]
    for i in range(N):
        if ans[i]==-1:
            l.append("0")
        else:
            l.append(str(ans[i]))
    print("".join(l))
