import sys
N,M=map(int,input().split())
SC={}
for i in range(1,N + 1):
    SC[i]=[]
for _ in range(M):
    s,c=map(int,input().split())
    SC[s].append(c*10**(N - s))

ans=[]
for h in SC[1]:
    tmp=h
    if(N == 1):
        ans.append(tmp)
    else:
        for t in SC[2]:
            if(N == 2 and tmp != 0):
                ans.append(tmp + t)
            else:
                for j in SC[3]:
                    if(len(str(tmp))!= 0):
                        ans.append(tmp + t + j)
        
if(ans == []):
    print(-1)
elif(len(str(min(ans))) == N):
    print(min(ans))
else:
    print(-1)