n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)]

for i in range(10**n):
    check = True
    
    for j in range(m):
            if n != len(str(i)):
                check = False
                break
            
            if l[j][0] > len(str(i)):
                check =False
                break
            
            if str(i)[l[j][0]-1] == str(l[j][1]):
                check = True
            
            else:
                check = False
                break
    
    c = i
    
    if check:
        ans = i
        break

if c == 10**n-1:
    print(-1)

else:
    print(ans)