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

a = str(int("".join(map(str, ans))))
if len(a) == N:
    print(a)
else:
    print(-1)