func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 250000;   int n, k, C[30], c[30];   vector<string> S;   bool anda, Z, term;   bool trythis(string X) {     bool ans = true;     for (int i = (0); i < (int)(k); i++) {       int cnt = 0;       for (int j = (0); j < (int)(n); j++)         if (S[i][j] != X[j]) cnt++;       if (!(cnt == 2 || (!cnt && Z))) ans = false;     }     return ans;   }   void proba(string X, int a, int b) {     swap(X[a], X[b]);     if (trythis(X)) {       cout << X << endl;       term = true;     }     swap(X[a], X[b]);   }   int main() {     while (cin >> k >> n) {       for (int i = (0); i < (int)(30); i++) C[i] = 0;       anda = true;       term = false;       S.resize(k);       for (int i = (0); i < (int)(k); i++) cin >> S[i];       for (int j = (0); j < (int)(n); j++) C[S[0][j] -  a ]++;       for (int i = (0); i < (int)(k); i++) {         for (int j = (0); j < (int)(30); j++) c[j] = 0;         for (int j = (0); j < (int)(n); j++) c[S[i][j] -  a ]++;         for (int j = (0); j < (int)(30); j++)           if (C[j] != c[j]) anda = false;       }       if (!anda) {         cout << -1 << endl;         continue;       }       for (int i = (0); i < (int)(30); i++)         if (C[i] > 1) Z = true;       for (int i = (0); i < (int)(k); i++)         for (int ii = (i + 1); ii < (int)(k); ii++) {           int cnt = 0;           for (int j = (0); j < (int)(n); j++)             if (S[i][j] != S[ii][j]) cnt++;           switch (cnt) {             case 0:               break;             case 2: {               vector<int> P;               for (int j = (0); j < (int)(n); j++)                 if (S[i][j] != S[ii][j]) P.push_back(j);               int t1 = P[0], t2 = P[1];               for (int c = (0); c < (int)(n); c++) {                 if (S[i][c] == S[i][t1]) {                   proba(S[i], c, t2);                   if (term) return 0;                 }                 if (S[i][c] == S[i][t2]) {                   proba(S[i], c, t1);                   if (term) return 0;                 }               }               proba(S[i], t1, t2);               if (term) return 0;               proba(S[ii], t1, t2);               if (term) return 0;               cout << -1 << endl;               return 0;             }             case 3: {               string X = S[i];               vector<int> P;               for (int j = (0); j < (int)(n); j++)                 if (S[i][j] != S[ii][j]) P.push_back(j);               for (int a = (0); a < (int)(3); a++)                 for (int b = (a + 1); b < (int)(3); b++) {                   proba(X, P[a], P[b]);                   if (term) return 0;                 }               cout << -1 << endl;               term = true;               return 0;             }             case 4: {               string X = S[i];               vector<int> P;               for (int j = (0); j < (int)(n); j++)                 if (S[i][j] != S[ii][j]) P.push_back(j);               for (int a = (0); a < (int)(4); a++)                 for (int b = (a + 1); b < (int)(4); b++) {                   proba(X, P[a], P[b]);                   if (term) return 0;                 }               cout << -1 << endl;               term = true;               return 0;             }             default: {               cout << -1 << endl;               term = true;               return 0;             }           }         }       if (!term) proba(S[0], 0, 1);     }     return 0;   }   