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