#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int N = 2505;
const int INF = 0x3f3f3f3f;
string s[N];
bool many[N];
int k, n, cntd[N];
void precalc() {
  string us = s[1];
  sort(us.begin(), us.end());
  bool ok = 1;
  for (int i = 1; i <= k; i++) {
    string ss = s[i];
    sort(ss.begin(), ss.end());
    ok &= (us == ss);
  }
  if (!ok) {
    puts("-1");
    exit(0);
  }
  for (int i = 1; i <= k; i++) {
    vector<int> cnt(30, 0);
    for (char x : s[i]) {
      cnt[x - 'a' + 1]++;
      many[i] |= (cnt[x - 'a' + 1] > 1);
    }
  }
  for (int i = 1; i <= k; i++) {
    for (int pos = 0; pos < n; pos++) {
      if (s[1][pos] != s[i][pos]) {
        cntd[i]++;
      }
    }
  }
}
int main() {
  cin >> k >> n;
  for (int i = 1; i <= k; i++) {
    cin >> s[i];
  }
  precalc();
  string ans = s[1];
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      swap(ans[i], ans[j]);
      bool ok = 1;
      for (int l = 1; l <= k; l++) {
        int cnt = cntd[l];
        if (s[1][i] != s[l][i] && ans[i] == s[l][i]) {
          cnt--;
        }
        if (s[1][i] == s[l][i] && ans[i] != s[l][i]) {
          cnt++;
        }
        if (s[1][j] != s[l][j] && ans[j] == s[l][j]) {
          cnt--;
        }
        if (s[1][j] == s[l][j] && ans[j] != s[l][j]) {
          cnt++;
        }
        ok &= (cnt == 2 || (cnt == 0 && many[l]));
      }
      if (ok) {
        cout << ans;
        return 0;
      }
      swap(ans[i], ans[j]);
    }
  }
  puts("-1");
}
