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

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

ans = -1
for num in range(1,1000):
    try:
        flag = True
        s_num = str(num)
        for s in S:
            if (s_num[s[0]] != s[1]):
                flag = False
                break
        if (flag):
            ans = num
            break
    except:
        pass

print (ans)