N,M = map(int,input().split())
nums = []
for _ in range(M):
    nums.append(list(map(int,input().split())))
    
if N == 1 and M == 0:
    print(0)
    exit()
for i in range(0,1000):
    if len(str(i)) == N:
        k = 0
        for j in range(M):
            s = nums[j][0]
            c = nums[j][1]
            if int(str(i)[s-1]) == c:
                k += 1
            if k == M:
                print(i)
                exit()
print(-1)