n, m = map(int, input().split())
x = [0] * n
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    if x[s] != 0 and x[s] != c or s == 0 and c == 0:
        print(-1)
        quit()
    x[s] = c
if x[0] == 0:
    x[0] = 1
print(''.join(map(str, x)))