n,m=list(int(i) for i in input().split())
S=[]
C=[]
ans=[0]*n
for _ in range(m):
    s,c=list(int(i) for i in input().split())
    S.append(s)
    C.append(c)
ans=[-1]*n
bool=True
for i in range(m):
    if ans[S[i]-1]==-1:
        ans[S[i]-1]=C[i]
    else:
        if ans[S[i]-1]!=C[i]:
            bool=False
            break
if bool is False:
    print(-1)
else:
    for i in range(n):
        if ans[i]==-1 or ans[i]==0:
            bool=False
            break
        else:
            break
    if bool is False:
        if n==1:
            print(0)
        else:
            print(-1)
    else:
        for i in range(n):
            if ans[i]==-1:
                print(0,end="")
            else:
                print(ans[i],end="")
