S = []
N,M = [int(i) for i in input().split(" ")]

for  _ in range(M):
    s,c = input().split(" ")
    S.append([int(s)-1,c])


flag = False
ans = -1
for i in range(1,1000):
    flag = True
    for s in S:
        if len(str(i)) != N or str(i)[s[0]] != s[1]:
            flag = False
            break
    if flag:
        ans = i
        break

print(ans)