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] is not None and answer[digit] != ci:
    # if answer[digit] != ci:
        print('-1')
        exit()
    
    answer[digit] = ci

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

if answer[0] == 0 and N != 1:
    print('-1')
    exit()

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