N, M=map(int, input().split(' '))
C=[None]*M
Num=[None]*M
f=0
for i in range(M):
    C[i], Num[i] = map(int, input().split(' '))

for i in range(10**(N-1), 10**N-1):
    STR_I = str(i)
    cnt=0
    #print(STR_I[-1])
    for j in range(M):
        #print(STR_I[-1*C[j]])
        if STR_I[C[j]-1]==str(Num[j]):
            cnt +=1
    if cnt==M:
        print(i)
        f=1
        break

if f==0:
    print('-1')