import sys
input = sys.stdin.readline

N, M = [int(x) for x in input().split()]
ans = ["0"] * N
sc = []
for _ in range(M):
    tmp = [int(x) for x in input().split()]
    sc.append(tmp)

for i in range(M):
    for j in range(i + 1, M):
        if 0 <= i < M and 0 <= j < M:
            if sc[i][0] == sc[j][0] and sc[i][1] != sc[j][1]:
                print(-1)
                sys.exit()

for k in sc:
    ans[k[0] - 1] = str(k[1])

ans = int("".join(ans))

if len(str(ans)) != N:
    print(-1)
else:
    print(ans)

