n, m = map(int, input().split())

x = [0] * n

for _ in range(m):
    s, c = map(int, input().split())
    if x[s-1] == 0:
        x[s-1] = c
    else:
        if c != x[s-1]:
            print(-1)
            exit()

if x[0] == 0:
    print(-1)
else:
    print("".join(map(str, x)))
