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):
    ans[S[i]-1]=C[i]
for i in range(n):
    if ans[i]==0 or ans[i]==-1:
        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="")
