#include <bits/stdc++.h>
using namespace std;
const int N = 5100;
string s[N];
bool flag[N];
int n, k;
bool check(string t) {
  for (int i = 0; i < n; ++i) {
    vector<int> pos;
    for (int j = 0; j < k; ++j)
      if (t[j] != s[i][j]) pos.push_back(j);
    if (pos.empty()) {
      if (flag[i]) return false;
    } else {
      if (pos.size() != 2) return false;
      swap(t[pos[0]], t[pos[1]]);
      if (t != s[i]) return false;
      swap(t[pos[0]], t[pos[1]]);
    }
  }
  return true;
}
bool dis(int i) {
  map<char, int> ps;
  for (auto c : s[i])
    if (++ps[c] >= 2) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  string ans;
  for (int i = 0; i < n; ++i) cin >> s[i], flag[i] = dis(i);
  string s0 = s[0];
  for (int i = 1; i < n; ++i) {
    vector<int> pos;
    for (int j = 0; j < k; ++j)
      if (s0[j] != s[i][j]) pos.emplace_back(j);
    if (pos.empty()) continue;
    if (pos.size() < 2 || pos.size() > 4) {
      cout << -1 << endl;
      return 0;
    }
    for (auto i : pos) {
      for (int j = 0; j < k; ++j) {
        if (j == i) continue;
        swap(s0[j], s0[i]);
        if (check(s0)) {
          cout << s0 << endl;
          return 0;
        }
        swap(s0[j], s0[i]);
      }
    }
    cout << -1 << endl;
    return 0;
  }
  swap(s0[0], s0[1]);
  cout << s0 << endl;
}
