#include <bits/stdc++.h>
using namespace std;
int first[5005][26];
string second[5005];
vector<int> pos[5005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int k, n;
  cin >> k >> n;
  bool ok = 1;
  int mm = 0;
  for (int i = 0; i < k; i++) {
    cin >> second[i];
    for (int j = 0; j < n; j++) {
      first[i][second[i][j] - 'a']++;
      mm = max(first[i][second[i][j] - 'a'], mm);
    }
    for (int j = 0; j < 26; j++) ok &= (first[i][j] == first[0][j]);
  }
  if (!ok)
    cout << (-1) << '\n';
  else if (k > 1) {
    int ma = 0;
    for (int j = 0; j < k; j++) {
      for (int i = 0; i < n; i++)
        if (second[0][i] != second[j][i]) pos[j].push_back(i);
      ma = max(ma, (int)pos[j].size());
    }
    if (ma > 4)
      cout << (-1) << '\n';
    else {
      string c = second[0];
      for (int p1 = 0; p1 < n; p1++)
        for (int p2 = p1 + 1; p2 < n; p2++) {
          swap(c[p1], c[p2]);
          ok = 1;
          for (int i = 0; i < k && ok; i++) {
            int difs = 0;
            bool pp1 = 0;
            bool pp2 = 0;
            for (auto y : pos[i]) {
              difs += (c[y] != second[i][y]);
              pp1 |= (p1 == y);
              pp2 |= (p2 == y);
            }
            if (!pp1) difs += (c[p1] != second[i][p1]);
            if (!pp2) difs += (c[p2] != second[i][p2]);
            ok &= (difs == 2 || (mm > 1 && difs == 0));
          }
          if (ok) {
            cout << (c) << '\n';
            return 0;
          }
          swap(c[p1], c[p2]);
        }
      cout << (-1) << '\n';
    }
  } else {
    swap(second[0][0], second[0][1]);
    cout << (second[0]) << '\n';
  }
  return 0;
}
