from collections import Counter


n, m = map(int, input().split())
s = [0] * m
c = [0] * m
for i in range(m):
    s[i], c[i] = map(int, input().split())
flg = False
for i in range(10 ** (n-1), 10 ** n):
    for j in range(m):
        if int(str(i)[s[j] - 1]) == c[j]:
            flg = True
        else:
            flg = False
            break
    if flg:
        print(i)
        exit()
print(-1)
