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

answer = [None] * N
for si, ci in sc:
    digit = si - 1
    if answer[digit] != ci:
        print(-1)
        exit()
    
    answer[digit] = ci

if answer[0] is None or answer[0] == 0:
    print(-1)
    exit()

for i, value in enumerate(answer):
    if answer[i] is None:
        answer[i] = 0

answer = ''.join(map(str, answer))
print(answer)
