#include <bits/stdc++.h>
using namespace std;
vector<string> vs;
int main() {
  int k, n;
  cin >> k >> n;
  string last;
  for (int i = 0; i < k; i++) {
    string s;
    cin >> s;
    string aux = s;
    sort(aux.begin(), aux.end());
    if (i == 0) last = aux;
    if (aux != last) {
      cout << -1 << endl;
      return 0;
    }
    vs.push_back(s);
  }
  if (k == 1) {
    swap(vs[0][1], vs[0][0]);
    cout << vs[0] << endl;
    return 0;
  }
  for (int i = 0; i < k; i++)
    for (int j = i + 1; j < k; j++) {
      vector<int> v;
      for (int l = 0; l < n; l++)
        if (vs[i][l] != vs[j][l]) v.push_back(l);
      if (v.size() == 0)
        continue;
      else if (v.size() > 4) {
        cout << -1 << endl;
        return 0;
      } else {
        string res;
        vector<string> weiss;
        for (int p : v) {
          for (int l = 0; l < n; l++)
            if (l != p) {
              swap(vs[i][p], vs[i][l]);
              weiss.push_back(vs[i]);
              swap(vs[i][p], vs[i][l]);
            }
        }
        for (string& s : weiss) {
          int flag = 0;
          for (int a = 0; a < k; ++a) {
            int diff = 0;
            set<char> ssss;
            for (int b = 0; b < n; ++b) {
              ssss.insert(s[b]);
              if (vs[a][b] != s[b]) ++diff;
            }
            if (diff != 2 && (diff != 0 || ssss.size() == n)) {
              flag = 1;
              break;
            }
          }
          if (flag) continue;
          res = s;
          break;
        }
        if (res.size() == 0)
          cout << -1 << endl;
        else
          cout << res << endl;
        return 0;
      }
    }
  swap(vs[0][0], vs[0][1]);
  cout << vs[0] << endl;
  return 0;
}
