n, m = map(int, input().split())
b = [list(map(int, input().split())) for _ in range(m)]
for ans in range(10 ** (n - 1), 10 ** n):
    if all(str(b[i][1]) == str(ans)[b[i][0] - 1] for i in range(m)):
        print(ans)
        break
else:
    print(-1)
