n, m = map(int, input().split())
s = [0]*m
c = [0]*m
for i in range(m):
    s[i], c[i] = map(int, input().split())

ans = -1

for num in range(1, 1000):
    num_car = str(num)

    con1 = len(num_car) == n

    con2 = True
    for i in range(m):
        if con1 and num_car[s[i] - 1] != str(c[i]):
            con2 = False

    if con1 and con2:
        ans = num
        break

print(ans)