import sys

N, M = map(int, input().split())

d = {}

for i in range(M):
    s, c = map(int, input().split())
    if s not in d:
        d[s] = c
    elif d[s] != c:
        print(-1)
        sys.exit()

# print(d)
# if d[1] == 0:
#     print(-1)
#     sys.exit()
ans = [0 for _ in range(N)]

for i in range(N):
    if i + 1 in d:
        ans[i] = d[i + 1]
if ans[0] == 0 and len(ans) != 1:
    print(-1)
else:
    print(*ans, sep="")
