#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using dd = long double;
namespace {
static bool constexpr dbg = 0;
ll constexpr N = 5100;
ll n, k;
int16_t le[N + 9][N + 9], ri[N + 9][N + 9], cnt[N + 9][N + 9];
string d[N + 9];
void init() {
  cin >> k >> n;
  for (ll i = 1, ii_ = (k); i <= ii_; ++i) cin >> d[i], d[i] = " " + d[i];
}
ll diff(ll i, ll i1, ll i2) {
  ll ret = (d[1][i1] != d[i][i1]) + (d[1][i2] != d[i][i2]);
  ret += le[i][i1 - 1] + ri[i][i2 + 1] + le[i][i2 - 1] - le[i][i1];
  return ret;
}
void solve() {
  for (ll i = 1, ii_ = (k); i <= ii_; ++i)
    for (ll j = 1, ii_ = (n); j <= ii_; ++j) ++cnt[i][d[i][j]];
  for (ll i = 2; i <= k; ++i)
    for (ll ch = 'a'; ch <= 'z'; ++ch)
      if (cnt[i][ch] != cnt[1][ch]) {
        cout << -1;
        return;
      }
  bool id = false;
  for (ll i = 'a'; i <= 'z'; ++i)
    if (cnt[1][i] > 1) id = true;
  for (ll i = 2; i <= k; ++i) {
    for (ll j = 1, ii_ = (n); j <= ii_; ++j)
      le[i][j] = le[i][j - 1] + (d[i][j] != d[1][j]);
    for (ll j = n; j >= 1; --j) ri[i][j] = ri[i][j + 1] + (d[i][j] != d[1][j]);
  }
  for (ll i = 1, ii_ = (n); i <= ii_; ++i)
    for (ll j = i + 1; j <= n; ++j) {
      swap(d[1][i], d[1][j]);
      bool ok = true;
      for (ll m = 2; m <= k; ++m) {
        ll t = diff(m, i, j);
        if (t == 2 || (t == 0 && id)) continue;
        ok = false;
        break;
      }
      if (ok) {
        cout << d[1].substr(1);
        return;
      }
      swap(d[1][i], d[1][j]);
    }
  cout << -1;
}
}  // namespace
int main() {
  if (!dbg) {
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  cout << fixed << setprecision(20);
  init();
  solve();
  return 0;
}
