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()

if x[0] is None:
    x[0] = 1

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

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