n,m=map(int,input().split())
sc=sorted([list(map(int,input().split())) for i in range(m)])
ans=[0 for i in range(n)]
res=True
ans[sc[0][0]-1]=sc[0][1]
for i in range(1,m):
    if sc[i][0]==sc[i-1][0] and sc[i][1]!=sc[i-1][1]:
        res=False
        break
    else:
        ans[sc[i][0]-1]=sc[i][1]

ans2=int("".join([str(i) for i in ans])) if res and not (n>1 and ans[0]==0) else -1
print(ans2)
