#include <bits/stdc++.h>
using namespace std;
const int Z = (int)1e5 + 111;
const int inf = (int)1e9 + 111;
const long long llinf = (long long)1e18 + 5;
const int MOD = (int)1e9 + 7;
string s[5555];
bool flag;
int n, k;
void ex(string f) {
  cout << f;
  exit(0);
}
bool ok(string t) {
  for (int i = 1; i <= k; ++i) {
    vector<int> pos;
    for (int j = 0; j < n; ++j) {
      if (t[j] != s[i][j]) pos.push_back(j);
    }
    if ((int)pos.size() == 2) {
      swap(s[i][pos[0]], s[i][pos[1]]);
      bool f = false;
      if (s[i] == t) f = true;
      swap(s[i][pos[0]], s[i][pos[1]]);
      if (f) continue;
    }
    if ((int)pos.size() == 0 && flag) continue;
    return false;
  }
  return true;
}
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(false);
  cin >> k >> n;
  for (int i = 1; i <= k; ++i) {
    cin >> s[i];
  }
  int ind = -1;
  for (int i = 2; i <= k; ++i) {
    if (s[i] != s[1]) ind = i;
  }
  if (ind == -1) {
    swap(s[1][0], s[1][1]);
    ex(s[1]);
  }
  vector<int> pos;
  for (int i = 0; i < n; ++i) {
    if (s[1][i] != s[ind][i]) pos.push_back(i);
  }
  if ((int)pos.size() > 4) {
    ex("-1");
  }
  map<char, int> cnt;
  flag = false;
  for (int i = 0; i < n; ++i) {
    cnt[s[1][i]]++;
    if (cnt[s[1][i]] > 1) flag = true;
  }
  for (int i = 0; i < (int)pos.size(); ++i) {
    for (int j = i + 1; j < (int)pos.size(); ++j) {
      string t = s[1];
      swap(t[pos[i]], t[pos[j]]);
      if (ok(t)) ex(t);
      t = s[ind];
      swap(t[pos[i]], t[pos[j]]);
      if (ok(t)) ex(t);
    }
  }
  ex("-1");
  return 0;
}
