#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
int n, k;
vector<char> a[5100];
vector<int> b[5100];
set<char> st;
vector<char> v, vv;
bool ffff = false;
bool check(int v) {
  int i, j;
  for (i = 1; i <= k; i++) {
    int cnt = 0;
    for (j = 0; j < n; j++) {
      if (a[i][j] != a[v][j]) cnt++;
    }
    if (cnt == 1 || cnt > 2) return false;
    if (cnt == 0 && i != v && !ffff) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  int i, j, kk;
  char c;
  cin >> k >> n;
  for (j = 0; j < n; j++) {
    cin >> c;
    a[1].push_back(c);
    vv.push_back(c);
  }
  sort(vv.begin(), vv.end());
  for (j = 0; j < n; j++) {
    if (st.count(vv[j]) > 0) {
      ffff = true;
      break;
    } else {
      st.insert(vv[j]);
    }
  }
  for (i = 2; i <= k; i++) {
    v.clear();
    for (j = 0; j < n; j++) {
      cin >> c;
      a[i].push_back(c);
      v.push_back(c);
    }
    sort(v.begin(), v.end());
    if (v != vv) {
      cout << -1;
      return 0;
    }
  }
  bool flag = true;
  for (i = 2; i <= k; i++) {
    int cnt = 0;
    for (j = 0; j < n; j++) {
      if (a[i][j] != a[1][j]) {
        b[i].push_back(j);
        cnt++;
      }
    }
    if (cnt > 4) {
      cout << -1;
      return 0;
    }
    if (cnt > 0) flag = false;
  }
  if (flag) {
    swap(a[1][0], a[1][1]);
    for (int h = 0; h < n; h++) cout << a[1][h];
    return 0;
  }
  for (i = 2; i <= k; i++) {
    for (j = 0; j < n; j++)
      for (kk = 0; kk < b[i].size(); kk++)
        if (j != kk || ffff) {
          swap(a[i][j], a[i][b[i][kk]]);
          if (check(i)) {
            for (int h = 0; h < n; h++) cout << a[i][h];
            return 0;
          }
          swap(a[i][j], a[i][b[i][kk]]);
        }
  }
  if (check(1) && ffff) {
    for (int h = 0; h < n; h++) cout << a[1][h];
    return 0;
  }
  cout << -1;
  return 0;
}
