N, M = [int(i) for i in input().split()]
S = [[i for i in input().split()] for _ in range(M)]
NN = int("9"*N) + 1
for i in range(NN):
    flag = True
    for j in S:
        tmp = str(i)
        try:
            if not tmp[int(j[0])-1] == j[1]:
                flag = False
                break
        except IndexError:
            flag = False
            break
    if flag:
        ans = i
        break
    else:
        ans = False
if ans:
    print(ans)
else:
    print(-1)