def main():
    n,m=map(int,input().split())
    Ans=[0]*n
    Flag=[False]*n
    for _ in range(m):
        s,c=map(int,input().split())
        s-=1
        if s==0 and c==0:
            return -1
        if Flag[s]==False:
            Ans[s]=c
            Flag[s]=True
        else:
            if Ans[s]!=c:
                return -1
    if Ans[0]==0:
        Ans[0]=1
    ans=''
    for a in Ans:
        ans+=str(a)
    return ans
    
if __name__=='__main__':
    print(main())