N,M= map(int,input().split())
s=[]
c=[]
ans=-1
for i in range(M):
    s_i,c_i=input().split()
    s.append(int(s_i))
    c.append(c_i)
for i in range(int("1"+"0"*(N-1)),int("9"*N)+1):
    ans_bool=True
    for j in range(M):
        ans_bool=ans_bool and str(i)[s[j]-1]==str(c[j])
    if ans_bool:
        ans=i
        
print(ans)
