N, M = map(int, input().split())
num = [-1] * N

ok = True
for _ in range(M):
    s, c = map(int, input().split())
    if num[s - 1] == -1 or num[s - 1] == c:
        num[s - 1] = c
    else:
        ok = False

if not ok:
    print(-1)
    exit()
elif num[0] == 0 or num[0] == -1:
    print(-1)
    exit()

for i, n in enumerate(num):
    if n == -1:
        num[i] = 0

ans = int("".join(map(str, num)))
print(ans)