N, M = [int(i) for i in input().split()]
S = set()
for i in range(M):
    a = input().split()
    S.add((int(a[0]),int(a[1])))
T = {x for x in range(100,1000) if (all({str(x)[s-1] == str(c) for (s,c) in S}) == True)}
if len(T) != 0:
    print(min(T))
else :
    print(-1)