line = list(input().split(" "))
n = int(line[0])
m = int(line[1])
num = []
for i in range(m):
    line = list(input().split(" "))
    num.append([int(line[0]),int(line[1])])
result = ["x" for i in range(n+1)]
for i in range(1000):
    if len(str(i)) == n:
        for j in range(m):
            if int(str(i)[num[j][0]-1]) != num[j][1]:
                break
            else:
                print(i)
                exit()
print(-1)