n,m = map(int,input().split())
sc = [input() for _ in range(m)]
ans = -1

for i in range(10**(n-1),10**n):
    i = str(i)
    ok = 0
    
    for j in sc:
        s,c = j.split()
        
        if i[int(s)-1] == c:
            ok += 1
        
    if ok == m:
        ans = int(i)
        break
        
print(ans)