#include <bits/stdc++.h>
using namespace std;
int Resi(int N,int K,int* L,char** A,char* S){
    string f[16];
    int vr[16][150],mx=0,pos,manji,br,z;
    bool q=false,t=false;
for (int i=1;i<=N;i++){
    for (int j=1;j<=L[i];j++){
        f[i][j]=A[i][j];
        vr[i][j]=A[i][j]-'a'+1;
    if (vr[i][j]>K){
       q=true;
    }
}
   if (L[i]>mx){
    mx=L[i];
    pos=i;
   }
}
if (q){
    return -1;
}
else {
         if (N==2){
                if (pos==1){manji=2;}
                else {manji=1;}
           for (int i=1;i<=L[pos]-L[manji]+1;i++){
              if (f[pos].substr(i,L[manji])==f[manji]){
                return -1;
                t=true;
                break;
              }
           }
                if (!t){
                      for (int i=L[manji]-1;i>=1;i--){
                       if (f[manji].substr(1,i)==f[pos].substr(L[pos]-i,i)){
                            for (int j=1;j<=L[pos];j++){
                                S[j]=f[pos][j];
                            }
                            for (int j=i+1,k=L[pos]+1;j<=L[manji];j++,k++){
                                S[k]=f[manji][j];
                            }
                            br=L[pos]+L[manji]-i;
                            z=1;
                            return br;
                            break;
                        }

                        if (f[pos].substr(1,i)==f[pos].substr(L[manji]-i,i)){
                                 for (int j=1;j<=L[manji]-i;j++){
                                    S[j]=f[manji][j];
                                 }
                                 for (int j=L[manji]-i+1,k=1;k<=L[pos];k++,j++){
                                    S[j]=f[pos][k];
                                 }
                        br=L[pos]+L[manji]-i;
                        z=1;
                        return br;
                        break;
                        }
                       }
                  }
                     if (z==0){
                        for (int i=1;i<=L[pos];i++){
                            S[i]=f[pos][i];
                        }
                        for (int i=1;i<=L[manji];i++){
                            S[L[pos]+i]=f[manji][i];
                        }
                        br=L[pos]+L[manji];
                        return br;
                     }
        }
}
}