#include <bits/stdc++.h>
using namespace std;
const int lmt = 5e3;
string s[lmt];
int acnt[lmt][26];
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (char c : s[i]) {
      acnt[i][c - 'a']++;
    }
  }
  if (k == 1) {
    for (int i = 2; i <= n; i++) {
      if (s[i] != s[i - 1]) {
        cout << -1 << "\n";
        return 0;
      }
    }
    cout << s[1] << "\n";
    return 0;
  }
  vector<string> ok;
  bool on = 0;
  for (int j = 0; j < 26; j++) {
    for (int i = 2; i <= n; i++) {
      if (acnt[i][j] != acnt[i - 1][j]) {
        cout << -1 << "\n";
        return 0;
      }
      if (acnt[i][j] > 1) on = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    bool brk = 0;
    for (int i2 = i + 1; i2 <= n; i2++) {
      vector<int> cnt;
      for (int j = 0; j < k; j++) {
        if (s[i][j] == s[i2][j]) continue;
        cnt.push_back(j);
      }
      if (cnt.empty()) continue;
      if (cnt.size() == 1 || cnt.size() > 4) {
        cout << -1 << "\n";
        return 0;
      }
      if (cnt.size() == 2 && !on) {
        cout << -1 << "\n";
        return 0;
      }
      if (cnt.size() == 2) {
        if (s[i][cnt[0]] != s[i2][cnt[1]] || s[i][cnt[1]] != s[i2][cnt[0]]) {
          cout << -1 << "\n";
          return 0;
        }
        string t = s[i], t2 = s[i2];
        swap(t[cnt[0]], t[cnt[1]]);
        ok.push_back(t);
        swap(t2[cnt[0]], t2[cnt[1]]);
        ok.push_back(t2);
        brk = 0;
        break;
      }
      if (cnt.size() == 3) {
        string t = s[i], t2 = s[i2];
        sort(t.begin(), t.end());
        sort(t2.begin(), t2.end());
        if (t != t2) {
          cout << -1 << "\n";
          return 0;
        }
        t = s[i], t2 = s[i2];
        for (int j = 0; j < 3; j++) {
          for (int p = 0; p < 3; p++) {
            for (int l = 0; l < 3; l++) {
              if (j == p || j == l || p == l) continue;
              t = s[i], t2 = s[i2];
              swap(t[cnt[j]], t[cnt[p]]);
              swap(t2[cnt[p]], t2[cnt[l]]);
              if (t != t2) continue;
              ok.push_back(t);
            }
          }
        }
        brk = 1;
        break;
      }
      if (cnt.size() == 4) {
        bool tyk = 0;
        for (int j = 0; j < 4; j++) {
          for (int h = 0; h < 4; h++) {
            for (int p = 0; p < 4; p++) {
              for (int l = 0; l < 4; l++) {
                if (j == h || j == p || j == l || h == p || h == l || p == l)
                  continue;
                string t = s[i], t2 = s[i2];
                swap(t[cnt[j]], t[cnt[h]]);
                swap(t2[cnt[p]], t2[cnt[l]]);
                if (t != t2) continue;
                ok.push_back(t);
                tyk = 1;
              }
            }
          }
        }
        if (!tyk) {
          cout << -1 << "\n";
          return 0;
        }
        brk = 1;
        break;
      }
    }
    if (brk) break;
  }
  if (ok.empty()) {
    swap(s[1][0], s[1][1]);
    cout << s[1] << "\n";
    return 0;
  }
  for (auto x : ok) {
    bool tyk = 1;
    for (int i = 1; i <= n; i++) {
      vector<int> mism;
      for (int j = 0; j < k; j++) {
        if (x[j] == s[i][j]) continue;
        mism.push_back(j);
      }
      if (mism.empty() && !on) {
        tyk = 0;
        break;
      }
      if (mism.empty()) continue;
      if (mism.size() == 1 || mism.size() > 2) {
        tyk = 0;
        break;
      }
      if (x[mism[0]] != s[i][mism[1]] || x[mism[1]] != s[i][mism[0]]) {
        tyk = 0;
        break;
      }
    }
    if (tyk) {
      cout << x << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}
