N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

matches = []
for i in range(1, 1000):
    if len(str(i)) == N:
        temp = True
        for s, c in sc:
            if str(i)[s - 1] != str(c):
                temp = False
        if temp: matches.append(i)
print(-1) if len(matches) == 0 else print(min(matches))