{
    N=$1;
    while(getline){
        if(A[$1]=="")A[$1]=$2;
        else ng+=A[$1]!=$2;
    }
    if(N>1){
        A[1]+=A[$1]=="";
        ng+=A[1]==0;
    }
    if(ng)print -1;
    else while(i++<N)printf A[i]+0;
}