#C
N, M = map(int, input().split())
s = [0] * M
c = [0] * M
for i in range(M):
    s[i], c[i] = map(int, input().split())
ans = -1

for i in range(1000):
    che = 0
    id = len(str(i))
    x = "00"+str(i)
    a = [int(x[-3]) , int(x[-2]), int(x[-1])]

    for j in range(M):
        che += abs(a[s[j]-1] - c[j])
    
    if (a[-N] != 0 or N == 1) and che == 0 and id == N:
        ans = i
        break
    else:
        continue 

print(ans)