n,m=map(int,input().split())
s=[]
c=[]
k=[-1]*(n+1)
for _ in range(m):
    s_,c_=map(int,input().split())
    s.append(s_)
    c.append(c_)
for i in range(m):
    if s[i]==1 and c[i]==0:
        print(-1)
        exit()
    if k[s[i]]==-1:
        k[s[i]]=c[i]
    elif k[s[i]]==c[i]:
        pass
    else:
        print(-1)
        exit()
ans=str(max(1,k[1]))
for i in range(2,n+1):
    ans+=str(max(0,k[i]))
print(ans)
