N,M = map(int,input().split())
SCdash = [[int(i) for i in input().split()] for m in range(M)]
SC = [[scc[0]-1,str(scc[1])] for scc in SCdash]
SG = [(0,10),(10,100),(100,1000)]
for x in range(*SG[N-1]):
    keta = str(x)
    if all([keta[s]==c for s,c in SC]):
        print(x)
        exit()
print(-1)
