N, M = map(int, input().split())

res = ['x' for _ in range(N)]

for i in range(M):
    s, c = map(int, input().split())

    if N != 1 and s == 1 and c == 0:
        print(-1)
        exit()
    elif res[s - 1] == 'x' or res[s - 1] == str(c):
        res[s - 1] = str(c)
    else:
        print(-1)
        exit()

if res[0] == 'x':
    res[0] = '1'

print(int(''.join(res).replace('x', '0')))
