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:
        r[x[i] - 1] = y[i]
        t[x[i] - 1] = 1
    else:
        if r[x[i] - 1] != y[i]:
            print(-1)
            exit()
if r[0] == 0 and t[0] != 0:
    if n == 1:
        print(0)
    elif n == 2:
        print(10)
    else:
        print(100)
else:
    print(*r, sep='')
