ms = [[j for j in str(i)] for i in range(100000)]
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
lis = []

for item in ms:
    if len(item) == n:
        for num, res in enumerate(s):
            if item[res[0] - 1] != str(res[-1]):
                break
            if num == len(s) - 1:
                lis.append(int("".join(item)))
if lis:
    print(min(lis))
else:
    print(-1)