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(10 ** n):
    num = str(i)
    is_good = True
    for j in range(m):
        if len(num) != n or num[s[j] - 1] != c[j]:
            is_good = False
    if is_good:
        print(i)
        exit()
print(-1)