N,M = list(map(int,input().split()))
S =[0] * M
C =[0] * M
ans = 10**N + 1
cnt = 0

for i in range(M):
    S[i],C[i] = list(map(int,input().split()))

for i in range(10**(N-1),10**N):
    x = str(i).zfill(N+1)
    for j in range(M):
        if int(x[S[j]]) == int(C[j]):
            cnt += 1
    if cnt == M and ans >= int(x) :
        ans = int(x)
    cnt  = 0

if ans != 10**N + 1 :
    print(ans)
else :
    print(-1)
