n,m=map(int,input().split())
c=[]
for i in range(m):
    c.append(list(map(int,input().split())))
ans=[0 for i in range(n)]
cnt=0
for i in range(m):
    if ans[c[i][0]-1]==0:
        ans[c[i][0]-1]=c[i][1]
    else:
        if ans[c[i][0]-1]==c[i][1]:
            continue
        else:
            cnt+=1
            break
if cnt!=0:
    print(-1)
else:
    if [1,0] in c:
        print(-1)
    else:
        if ans[0]==0:
            ans[0]=1
        for i in range(n):
            ans[i]=str(ans[i])
        aa=''.join(ans)
        print(aa)