n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]

value = [-1] * n
answer = 0

for l in sc:
    if value[l[0]-1] != -1 and value[l[0]-1] != l[1]:
        answer = -1
    else:
        value[l[0]-1] = l[1]

if value[0] == 0:
    answer = -1
elif value[0] == -1:
    value[0] = 1
elif n >= 2:
    for i in range(1, n):
        if value[i] == -1:
            value[i] = 0

if answer == -1:
    print(answer)
else:
    print("".join(map(str, value)))