n, m = map(int, input().split())

cond = []
for _ in range(m):
    s, c = map(int, input().split())
    cond.append((s, c))
inf = float('infinity')
ans = inf
for i in range(1, 10 ** n):
    string = str(i)
    if len(string) != n:
        continue
    for s, c in cond:
        if len(string) < s:
            break
        if string[s - 1] == str(c):
            continue
        else:
            break
    else:
        ans = min(ans, i)
if ans == inf:
    print(-1)
else:
    print(ans)