def MI():return map(int,input().split())
N,M=MI()
sc=[]
for i in range(M):
    x,y=MI()
    sc.append((x,y))
for i in range(0,10**3):
    h=str(i)
    if len(h)==N:
        if all([h[s-1]==str(c) for (s,c) in sc]):
            print(i)
            exit()
print(-1)
        