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

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

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

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

r = ''.join(res)
print(int(r.replace('x', '1')))
