n, m = map(int, input().split())
x = [0] * m
y = [0] * m
r = [0] * n
t = [0] * n
for i in range(m):
    x[i], y[i] = map(int, input().split())
    if t[x[i] - 1] == 0 and r[x[i] - 1] == y[i]:
        r[x[i] - 1] = y[i]
        t[x[i] - 1] = 1
    else:
        print(-1)
        exit()
if n > 1 and r[0] == 0:
    print(-1)
else:
    print(*r, sep='')
