import sys

N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
ans = [0 for _ in range(N)]
ume = [False for _ in range(N)]
for i, j in sc:
    if not ume[i-1]:
        ume[i-1] = True
        ans[i-1] = j
    else:
        if ans[i-1] != j:
            print(-1)
            sys.exit()

if not ume[0]:
    ans[0] = 1
elif ans[0] == 0 and N != 1:
    print(-1)
    sys.exit()

for i in ans:
    print(i, end="")