import sys
N, M = map(int, input().split())
S = []
C = []
for _ in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
    if s == 1 and c == 0:
        print(-1)
        sys.exit()

ans = [None] * N


for s, c in zip(S, C):
    if ans[s - 1] is None:
        ans[s - 1] = c
    elif ans[s - 1] == c:
        continue
    else:
        print(-1)
        sys.exit()

for x in range(N):
    if ans[x] is None:
        ans[x] = 0
    print(ans[x], end="")

print()
