N,M=map(int,input().split())
s,c=[0]*M,[0]*M
flg=0
cond=[]
for i in range(M):
    tmp=list(map(int,input().split()))
    if not tmp in cond:
        cond.append(tmp)
B=[i[0] for i in cond]
B=list(set(B))
if len(B)!=len(cond):
    flg=-1
else:
    num=[0]*N
    for i,j in list(cond):
        num[i-1]=j
    flg=''
    for i in num:
        flg+=str(i)
    flg=int(flg)
print(flg)