N, M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]
ans = "0"*N
okflg = 1
for i in range(M):
    if N > 1 and sc[i][0] == 4-N and sc[i][1] == 0:
        okflg = 0
    if ans[sc[i][0]-1] == "0":
        ans = list(ans)
        ans[sc[i][0]-1] = str(sc[i][1])
        ans = "".join(ans)
    else:
        if ans[sc[i][0]-1] != str(sc[i][1]):
            okflg = 0
if okflg == 0:
    print(-1)
elif len(str(int(ans))) == N:
    print(int(ans))
else:
    print(int("1"+str(ans[1:])))