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

ans = [0 for _ in range(n)]
for x in sc:
    p = x[0]-1
    if ans[p] == 0 or ans[p] >= x[1]:
        ans[p] = x[1]
    else:
        print(-1)
        exit()
num = ''
for x in ans:
    num += str(x)
print(int(num) if len(str(int(num))) == n else -1)