n, m = map(int, input().split())
ans = 1000
sc = [list(map(int, input().split())) for i in range(m)]
for j in range(1000):
    if len(str(j)) == n:
        for k in range(m):
            if str(j)[sc[k][0] - 1] != str(sc[k][1]):
                break
            elif k == m-1:
                print(j)
                exit()
print(-1)