#ABC157 Guess the number
n,m = map(int,input().split())
sc = [input().split() for _ in range(m)]
ans = []
for i in range(0,10**n):
    cnt = 0
    seq = str(i)
    for j in range(m):
        if seq[int(sc[j][0])-1] == sc[j][1]:
            print(seq[int(sc[j][0])-1])
            cnt += 1
    if cnt == m:
        ans.append(i)
        
if len(ans) == 0:
    print('-1')
else:
    print(min(ans))