#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(long long N, int pos) { return (bool)(N & (1LL << pos)); }
int k, n;
int ase[30];
string arr[2505];
vector<int> pos;
vector<int> adj[5005];
vector<string> vec;
int main() {
  cin >> k >> n;
  for (int i = 1; i <= k; i++) {
    cin >> arr[i];
  }
  if (n == 1) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 2) {
    swap(arr[1][0], arr[1][1]);
    string s1 = arr[1];
    swap(arr[1][0], arr[1][1]);
    for (int i = 1; i <= k; i++) {
      if (arr[i] != arr[1]) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << s1 << endl;
    return 0;
  }
  if (k == 1) {
    swap(arr[1][0], arr[1][1]);
    cout << arr[1] << endl;
    return 0;
  }
  bool hobe = true, first = true;
  int nul = 0;
  for (int i = 2; i <= k; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (arr[1][j] != arr[i][j]) {
        if (first) pos.push_back(j);
        adj[i].push_back(j);
        cnt++;
      }
    }
    if (adj[i].size() == 0) nul++;
    if (cnt == 1 || cnt > 4) hobe = false;
    if (cnt > 0 && first) first = false;
  }
  if (nul == k - 1) {
    swap(arr[1][0], arr[1][1]);
    cout << arr[1] << endl;
    return 0;
  }
  if (!hobe)
    cout << -1 << endl;
  else {
    for (int i = 0; i < pos.size(); i++) {
      for (int j = 0; j < n; j++) {
        if (pos[i] == j) continue;
        swap(arr[1][pos[i]], arr[1][j]);
        vec.push_back(arr[1]);
        swap(arr[1][pos[i]], arr[1][j]);
      }
    }
    int mx = 0;
    for (int i = 0; i < n; i++) {
      ase[arr[1][i] - 'a']++;
      mx = max(mx, ase[arr[1][i] - 'a']);
    }
    if (mx > 1) vec.push_back(arr[1]);
    string ans = "-1";
    for (int p = 0; p < vec.size(); p++) {
      int cnt = 0;
      for (int i = 2; i <= k; i++) {
        int mis = 0;
        char m1[5001], m2[5001];
        for (int j = 0; j < n; j++) {
          if (vec[p][j] != arr[i][j]) {
            mis++;
            m1[mis] = vec[p][j];
            m2[mis] = arr[i][j];
          }
        }
        if (mis == 2 && m1[1] == m2[2] && m1[2] == m2[1])
          cnt++;
        else if (mis == 0 && mx >= 2)
          cnt++;
        else
          break;
      }
      if (cnt == k - 1) {
        ans = vec[p];
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
