n, m = map(int, input().split())
L = ["0" for i in range(n)]
done = []
flag = False
for i in range(m):
    a, b = map(int, input().split())
    if a in done and L[a - 1] != str(b):
        flag = True
        break
    L[a - 1] = str(b)
    done.append(a)

for i in range(len(L)):
    if L[i] == "0":
        flag = True
        break
    else:
        break

if flag:
    print(-1)
else:
    print("".join(L))
