n, m = list(map(int, input().split()))
s = []
c = []
for _ in range(m):
    s_i, c_i = list(input().split())
    s.append(int(s_i))
    c.append(c_i)
for i in range(1, 10 ** n):
    num = list(str(i))
    for j in range(m):
        if len(num) < s[j] or num[s[j] - 1] != c[j]:
            break
    else:
        print(i)
        exit()
print(-1)