from sys import stdin
def main():
    readline=stdin.readline
    N,M=map(int,readline().split())
    s=[0]*M
    c=[0]*M
    for i in range(M):
        a,b=map(int,readline().split())
        s[i]=a
        c[i]=b

    res=[-1,0,0]
    flag=[False]*3
    for i in range(M):
        if flag[s[i]-1]==False:
            flag[s[i]-1]=True
            res[s[i]-1]=c[i]
        else:
            if res[s[i]-1]!=c[i]:
                print(-1)
                break
    else:
        for i in range(M):
            res[s[i]-1]=c[i]
        if res[0]==-1:
            res[0]=1
            print("".join(map(str,res)))
        elif res[0]==0:
            print(-1)
        else:
            print("".join(map(str,res)))

if __name__=="__main__":
    main()