N,M=map(int,input().split())
s=[0]*M
c=[0]*M
ans=[0]*N
for i in range(M):
    s[i],c[i]=map(int,input().split())
flg=0
for i in range(M):
    if s.count(s[i])>=2:
        flg+=1
if flg>=1:
    print("-1")
else:
    if 1 not in s and N!=1:
        ans[0]=1
    for i in range(M):
        ans[s[i]-1]=c[i]
    for i inrange(N):
        print(ans[i],end="")