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

x = [None] * n

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

x = [0 if i is None else i for i in x]

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