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 = 0

for i in range(1,1000):
    try:
        if [str(i)[s[0]] == s[1] for s in S].count(True) == M and len(str(i)) == N:
            ans = i
            flag = True
            break
    except:
        pass

if flag:
    print(ans)
else:
    print("-1")