N, M = list(map(int, input().split()))

numlist = ['-'] * N
answer = 0
for m in range(M):
    s, c = list(map(int, input().split()))
    if numlist[s - 1] == '-':
        numlist[s - 1] = c
    else:
        if numlist[s - 1] != c:
            answer = -1
            break


if numlist[0] == '-' or numlist[0] == 0:
    if N == 1:
        answer = 0
    else:
        answer = -1
else:
    strlist = []
    for num in numlist:
        num = 0 if num == '-' else num
        strlist.append(str(num))
    answer = ''.join(strlist)
print(answer)
