N,M=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(M)]

answer=[]

if N==1:
    for j in range(10):
        for i in range(M):
            if int(str(j)[sc[i][0]-1])==sc[i][1]:
                a+=1
            else:
                break
        if a==M:
            answer.append(j)
else:
    for j in range(10**(N-1),10**N):
        a=0
        for i in range(M):
            if int(str(j)[sc[i][0]-1])==sc[i][1]:
                a+=1
            else:
                break
        if a==M:
            answer.append(j)
if len(answer)>=1:
    print(min(answer))
    #print(answer)
else:
    print(-1)
