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 = ""
for i in range(1, N + 1):
    if i in d:
        ans += str(d[i])
    else:
        ans += "0"
print(ans)
