N, M=map(int,input().split())
num=[list(map(int,input().split())) for i in range(M)]
 
for i in range(1000):
    n=str(i)
    if len(n)!=N:
        continue
    if all([n[s-1]==str(c) for s,c in num]):
        print(n)
        break
else:
    print(-1)