n, m = map(int, input().split())
lis = [list(map(int, input().split())) for _ in range(m)]
ans = -1
for i in range(1000):
    if len(str(i)) != n:
        continue
    else:
        s = 0
        for j in lis:
            if str(i)[j[0]-1] == str(j[1]):
                s += 1
    print(s)
    if s == m:
        ans = i
        break
print(ans)            