input = raw_input

n, m = map(int, input().split(" "))
pairs = set( [tuple(map(int, input().split(" "))) for _ in range(m)] )
#pairs = sorted(tmp , key=lambda x: x[0])

values = [None] * (n+1)

flag = True
for s, c in pairs:
    if s == 1 and c == 0 and n != 1:
        flag = False
        break

    if values[s] is not None:
        flag = False
        break

    values[s] = c

if flag:
    out = 0
    for i in range(1, n+1):
        value = values[i]
        if value is None:
            if i == 1 and n != 1:
                value = 1
            else:
                value = 0

        j = n - i + 1
        out += value * (10 ** (j-1)) 

else:
    out = -1

print(out)