N, M = map(int, input().split())
SC = []
for _ in range(M):
    s, c = map(int, input().split())
    SC.append((s - 1, c))

for n in range(1000):
    s = str(n)
    if len(s) == N and all(int(s[i]) == c for i, c in SC):
        print(n)
        break
else:
    print(-1)