n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
cnt = 0

for i in range(1000):
    il = len(str(i))
    if il == n:
        for j in range(m):
            if il >= j + 1:
                num = s[j][0] - 1
                k = str(i)
                if str(s[j][1]) == k[num]:
                    cnt += 1
                num = 0
        if cnt == n:
            print(i)
            exit()
        else:
            cnt = 0

print(-1)