#include <bits/stdc++.h>

#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define mod 1000000007
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back

using namespace std;

bool ch[15];
vector<pair<int,string>>v;
vector<string>da;
string solve(int ind,int N){
    int br=0,cnt=-1;
    int ok=0;

    while(true){
        ok++;
        ch[ind]=true;
        for (int i=1;i<N;i++){
            if (ch[i])continue;
            for (int p=0;p<v[ind].se.size();p++){
                int j=0;
                for (;j<v[i].se.size();j++){
                    if (p+j==v[ind].se.size())break;
                    if (v[ind].se[p+j]!=v[i].se[j]){
                        j=-1;
                        break;
                    }
                    if (j==v[i].se.size()-1){
                        j=-2;
                        break;
                    }
                }
                if (j==-1)continue;
                ch[i]=true;
                if (j==-2)break;

                for (;j<v[i].se.size();j++)v[ind].se.pb(v[i].se[j]);
                break;
            }
        }
        br=0;
        for (int i=0;i<N;i++){
            reverse(all(v[i].se));
            if (ch[i])br++;
        }
        if (br==cnt)break;
        if (br==N)break;
        cnt=br;
    }
    if (ok%2==1)reverse(all(v[ind].se));
    return v[ind].se;
}

bool proveri(string ans,string p){
    int cnt=0;
    for (int i=0;i<ans.size();i++){
        bool t=false;
        for (int j=0;j<p.size();j++){
            if (p[j]!=ans[i+j])t=true;
        }
        if (!t)cnt++;
        if (i+p.size()==ans.size())break;
    }
    if (cnt>1)return true;
    return false;
}

int Resi(int N, int K, int* L, char** A, char* S){
    for (int i=1;i<=N;i++){
        for (int j=1;j<=L[i];j++){
            if (A[i][j]-'a'>K)return -1;
        }
        for (int j=1;j<=N;j++)if (i!=j and A[i]==A[j])return -1;
    }


    memset(ch,false,sizeof(ch));

    for (int i=1;i<=N;i++){
        string p;
        for (int j=1;j<=L[i];j++)p.pb(A[i][j]);
        v.pb({(int)p.size(),p});
        da.pb(p);
    }
    sort(rall(v));
    string ans;
    for (int i=0;i<N;i++)if (!ch[i])ans+=solve(i,N);
    for (auto i:da){
        if (proveri(ans,i))return -1;
    }

    for (int i=0;i<ans.size();i++){
        S[i+1]=ans[i];
    }
    return ans.size();
}

/*


3 26
ave bc cd

2 2
ababa aba
int main(){
	int N, K;
	cin >> N >> K;
	char** A = new char*[N+1];
	int* L = new int[N+1];
	char* S = new char[65536];
	for (int i=1; i<=N; i++) {
		string s;
		cin >> s;
		A[i] = new char[s.size() + 2];
		copy(s.begin(), s.end(), A[i]+1);
		A[i][s.size() + 1] = 0;
		L[i] = s.size();
	}
	int res = Resi(N, K, L, A, S);


	cout << res << '\n';
	if (res >= 0) {
		for (int i=1; i<=res; i++)
			cout << S[i];
		cout << '\n';
	}

	for (int i=1; i<=N; i++)
		delete[] A[i];
	delete[] A;
	delete[] L;
	delete[] S;
    return 0;
}

*/