S = []
N,M = [int(i) for i in input().split(" ")]

for  _ in range(M):
    S.append([int(i) for i in input().split(" ")])


flag = False
ans = []

for i in range(1,1000):
    try:
        if [int(str(i)[s[0]-1]) == s[1] for s in S].count(True) == M and len(str(i)) == N:
            ans.append(i)
            flag = True
    except:
        pass

if flag:
    print(min(ans))
else:
    print("-1")