from sys import exit

N, M = [int(x) for x in input().split()]

result = [-1] * N

for i in range(1, M + 1):
    s, c = [int(x) for x in input().split()]

    if s == 1 and c == 0:
        print(-1)
        exit()

    if result[s-1] != -1 and result[s-1] != c:
        print(-1)
        exit()

    result[s - 1] = c

if result[0] == -1:
    result[0] = 1

print(''.join([str(x) if x != -1 else str(0) for x in result]))
