N, M = map(int, input().split())
ans = [0] * N
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        print(-1)
        exit()
    if ans[s-1] == 0 or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()

if int("".join(map(str, ans))) == 0:
    print(-1)
    exit()

if ans[0] == 0:
    ans[0] = 1

print(int("".join(map(str, ans))))
