N,M=map(int,input().split())
ans=['o']*N
s=[0]*M
c=[0]*M
flag=True
for i in range(M):
    s[i],c[i]=map(int,input().split())
for m in range(M):
    c[m]=str(c[m])
if M>1:
    for j in range(M):
        if ans[s[j]-1].isnumeric():
            flag=(ans[s[j]-1]==str(c[j]))
            break
        else:
            ans[s[j]-1]=str(c[j])
elif M==1:
    ans[0]=c[0]
for k in range(M):
    ans[k]=str(ans[k])
if flag==False:
    print(-1)
elif len(ans)==1:
    if ans[0]!='o':
        print(ans[0])
    else:
        print(-1)
elif ans[0]=='0':
    print(-1)
else:
    for l in range(N):
        if ans[l]=='o':
            ans[l]='0'
    ans=''.join(ans)
    print(ans)