N, M = map(int, input().split())
number = [0 for i in range(N)]
judge = []


for i in range(M):
    keta, num = map(int, input().split())
    keta -= 1
    judge.append(keta)
    number[keta] = num


if (N < M or len(judge) != len(set(judge))):
    ans = -1


if (number[0] == 0 and N != 1):
    ans = -1
else:
    ans = ''
    for i in range(len(number)):
        ans += str(number[i])
    
    ans = int(ans)


print(ans)