n, m = map(int, input().split())

s = [[int(x) for x in input().split()] for _ in range(m)]

for i in range(1, 1000):
    if len(str(i)) == n:
        ans = i
        for j in range(m):
            pos = s[j][0]
            if str(i)[pos-1:pos] != str(s[j][1]):
                ans = -1
                break
        if ans != -1:
            break
print(ans)
