#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> k >> n;
  string s[k];
  for (long long i = 0; i < k; i++) cin >> s[i];
  int d = 0, dt;
  vector<int> in, in1;
  string te, t1;
  char ch[n];
  int c1[26];
  for (long long h = 1; h < k; h++) {
    in1.clear();
    t1.clear();
    dt = 0;
    for (long long i = 0; i < n; i++) {
      if (s[0][i] != s[h][i]) {
        dt++;
        in1.push_back(i);
        t1 += s[0][i];
      }
    }
    if (dt >= d) {
      in.clear();
      te.clear();
      d = dt;
      for (long long i = 0; i < d; i++) {
        in.push_back(in1[i]);
        te += t1[i];
      }
    }
  }
  bool v = 0, v1;
  int d1 = 0;
  memset(c1, 0, sizeof(c1));
  if (d > 4) {
    cout << -1 << "\n";
    return 0;
  }
  for (long long i = 0; i < n; i++) ch[i] = s[0][i];
  for (long long j = 0; j < n; j++) c1[s[0][j] - 'a']++;
  if (d == 0) {
    ch[0] = s[0][1];
    ch[1] = s[0][0];
    for (long long i = 0; i < n; i++) cout << ch[i];
    cout << "\n";
    return 0;
  }
  do {
    v1 = 0;
    int ct[26];
    for (long long i = 0; i < d; i++) {
      ch[in[i]] = te[i];
    }
    for (long long i = 0; i < k; i++) {
      d1 = 0;
      memset(ct, 0, sizeof(ct));
      for (long long j = 0; j < n; j++)
        if (s[i][j] != ch[j]) {
          d1++;
        }
      for (long long j = 0; j < n; j++) ct[s[i][j] - 'a']++;
      for (long long j = 0; j < 26; j++)
        if (ct[j] != c1[j]) v1 = 1;
      if (d1 == 0) {
        bool yu = 0;
        for (long long j = 0; j < 26; j++)
          if (ct[j] > 1) yu = 1;
        if (!yu) {
          v1 = 1;
          break;
        }
      } else if (d1 != 2) {
        v1 = 1;
        break;
      }
    }
    if (!v1) {
      v = 1;
      break;
    }
  } while (next_permutation(in.begin(), in.end()));
  if (!v) {
    cout << -1 << "\n";
  } else {
    for (long long i = 0; i < n; i++) cout << ch[i];
    cout << "\n";
  }
  return 0;
}
