import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
nl = lambda: list(map(int, stdin.readline().split()))

n, m = na()
ans = 10 ** 9 + 7
sc = [na() for _ in range(m)]
found = False
for i in range(10 ** n):
    st = str(i).zfill(n)
    flag = True
    for s, c in sc:
        if st[int(s) - 1] != str(c):
            flag = False
            break
        else:
            #print(i, len(st), len(str(i)))
            if len(st) != len(str(i)) and len(st) - len(str(i)) <= s:
                flag = False
                break
    if flag:
        found = True
        ans = min(ans, i)
if found and ans != 0:
    print(ans)
else:
    print(-1)