dummy = list(map(int, input().split(" ")))
N = dummy[0]
M = dummy[1]

s = []
c = []
for i in range (M):
    dummy = list(map(int, input().split(" ")))
    s.append(dummy[0])
    c.append(dummy[1])



for i in range (0, 1000):
    if(len(str(i)) == N):
        for j in range(M):
            if not (str(i)[s[j] - 1] == str(c[j])):
                break
            if (j == M - 1):
                print(i)
                exit()
print(-1)