N,M = map(int,input().split())
sc = [[0,0]]*M
ans = [0]*N
f = True
ans = -1
for i in range(M):
    sc[i] = list(map(int,input().split()))

for i in range(1000):
    str_i = str(i)
    if (len(str_i) == N):
        f = True
        for j in range(M):
            f &= (str_i[sc[i][0]-1] == str(sc[i][1]))
        if (f):
            ans = i
            break

print(ans)