n,m = map(int, input().split())

sc = [tuple(map(int, input().split())) for _ in range(m)]

for i in range(1000):
    
    k = str(i)
    
    if len(k) == n and all([k[s-1]==str(c) for s,c in sc]):
        print(k)
        exit()

print(-1)