N,M = map(int,input().split())
SC = [map(int,input().split()) for i in range(M)]
ans = [0 for i in range(N)]
ans[0] = 1
changed = [False for i in range(N)]
for i,j in SC:
    if changed[i-1]:
        if ans[i-1]==j:
            pass
        else:
            print(-1)
            exit()
    else:
        changed[i-1]=True
        if(i==1 and j==0):
            print(-1)
            exit()
        else:
            ans[i-1]=j
res = ""
for i in ans:
    res += str(i)
print(res)