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