N, M = map(int, input().split())
digits = [-1] * N
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if (s == 0 and c == 0) or (digits[s] != -1 and digits[s] != c):
        print(-1)
        exit()
    digits[s] = c
ans = ''
if digits[0] == -1:
    ans += '1'
else:
    ans += str(digits[0])
for i in range(1, N):
    if digits[i] == -1:
        ans += '0'
    else:
        ans += str(digits[i])
print(ans)
