#include <bits/stdc++.h>
using namespace std;

int n, k;
string s[15];
int hashes[15];
int br[15];

bool imachar[26];

const int INF = 1000000007;

string subtask1(){
    string rs = "";
    queue <string> q;
    q.push("a");
    q.push("b");
    while(!q.empty()){
        string str = q.front();
        q.pop();
        int x = str.size();
        for(int j=1; j<=n; j++){
            br[j] = 0;
        }
        for(int i=0; i<x; i++){
            for(int j=1; j<=n; j++){
                if(i+s[j].size()-1 >= x) continue;
                for(int k=0; k<s[j].size(); k++){
                    if(str[i+k] != s[j][k]) break;
                    if(k == s[j].size()-1) br[j]++;
                }
            }
        }
        for(int j=1; j<=n; j++){
            if(br[j] != 1) break;
            if(j == n){
                return str;
            }
        }
        if(str.size() < 18){
            q.push(str+'a');
            q.push(str+'b');
        }
    }
    return rs;
}

int podstring(string s1, string s2){
    int a = s1.size();
    int b = s2.size();
    int br = 0;
    for(int i=0; i<b; i++){
        if(i+a-1 >= b) break;
        for(int j=0; j<a; j++){
            if(s1[j] != s2[i+j]) break;
            if(j == a-1) br++;
        }
    }
    return br;
}

void ispisi(string s, char* S){
    int cnt = 0;
    for(auto c : s){
        cnt++;
        S[cnt] = c;
    }
    return;
}

int Resi(int N, int K, int* L, char** A, char* S){
    n = N;
    k = K;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=L[i]; j++){
            s[i] += A[i][j];
        }
    }
    if(K == 2){
        string g = subtask1();
        if(g.size() == 0){
            return -1;
        }
        int cnt = 0;
        for(auto c : g){
            cnt++;
            S[cnt] = c;
        }
        return cnt;
    }
    if(N == 2){
        string resenje = "";
        int sz = INF;
        if(s[1].size() > s[2].size()) swap(s[1], s[2]);
        if(podstring(s[1], s[2]) >= 2){
            return -1;
        }
        if(podstring(s[1], s[2]) == 1){
            ispisi(s[2], S);
            return s[2].size();
        }
        for(auto c : s[1]){
            imachar[c-'a'] = 1;
        }
        for(auto c : s[2]){
            imachar[c-'a'] = 1;
        }
        for(int i=k; i<26; i++){
            if(imachar[i]) return -1;
        }
        for(int i=0; i<k; i++){
            string rs = s[1] + char('a'+i) + s[2];
            if(podstring(s[1], rs) == 1 && podstring(s[2], rs) == 1){
                if(sz > rs.size()){
                    sz = rs.size();
                    resenje = rs;
                }
            }
        }
        //cout << resenje << " je resenje\n";
        int a = s[1].size();
        int b = s[2].size();
        for(int i=0; i<b; i++){
            string pr = "";
            for(int j=i; j<b; j++){
                pr += s[2][j];
            }
            string rs = s[1] + pr;
            if(podstring(s[1], rs) == 1 && podstring(s[2], rs) == 1){
                if(sz > rs.size()){
                    sz = rs.size();
                    resenje = rs;
                }
            }
            pr = "";
            for(int j=0; j<=i; j++){
                pr += s[2][j];
            }
            rs = pr + s[1];
            if(podstring(s[1], rs) == 1 && podstring(s[2], rs) == 1){
                if(sz > rs.size()){
                    sz = rs.size();
                    resenje = rs;
                }
            }
        }
        for(int i=0; i<a; i++){
            string pr = "";
            for(int j=i; j<a; j++){
                pr += s[1][j];
            }
            string rs = s[2] + pr;
            if(podstring(s[1], rs) == 1 && podstring(s[2], rs) == 1){
                if(sz > rs.size()){
                    sz = rs.size();
                    resenje = rs;
                }
            }
            pr = "";
            for(int j=0; j<=i; j++){
                pr += s[1][j];
            }
            rs = pr + s[2];
            if(podstring(s[1], rs) == 1 && podstring(s[2], rs) == 1){
                if(sz > rs.size()){
                    sz = rs.size();
                    resenje = rs;
                }
            }
        }
        for(int i=0; i<26; i++){
            for(int j=0; j<26; j++){
                string rs = s[1] + char('a' + i) + char('a' + j) + s[2];
                if(podstring(s[1], rs) == 1 && podstring(s[2], rs) == 1){
                    if(sz > rs.size()){
                        sz = rs.size();
                        resenje = rs;
                    }
                }
            }
        }
        if(sz == INF) return -1;
        ispisi(resenje, S);
        return sz;
    }
    return -2;
}

/*int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	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;
}*/