N, M = map(int, input().split())

data = [-1] * N
for _ in range(M):
    s, c = map(int, input().split())
    if data[s - 1] != -1 and data[s - 1] != c:
        print(-1)
        exit()
    else:
        data[s - 1] = c

res = 0
for idx, d in enumerate(data):
    if d == -1 or d == 0 and idx == N - 1:
        res = -1
        break
    if d != -1:
        res += d * pow(10, N - (idx + 1))
print(res)