#include <bits/stdc++.h>
using namespace std;
int lcp[5005][5005];
string s[5005];
int n, k;
bool self_swap;
bool check(int id, int l, int r) {
  vector<int> dif(0);
  if (s[id][l] != s[1][l]) dif.push_back(l);
  if (s[id][r] != s[1][r]) dif.push_back(r);
  for (int cur = 1; cur < l;) {
    cur += lcp[id][cur];
    if (cur < l) {
      dif.push_back(cur);
      cur++;
      if (dif.size() > 2) return false;
    }
  }
  for (int cur = l + 1; cur < r;) {
    cur += lcp[id][cur];
    if (cur < r) {
      dif.push_back(cur);
      cur++;
      if (dif.size() > 2) return false;
    }
  }
  for (int cur = r + 1; cur <= n;) {
    cur += lcp[id][cur];
    if (cur <= n) {
      dif.push_back(cur);
      cur++;
      if (dif.size() > 2) return false;
    }
  }
  if (dif.size() == 2) {
    bool ok = true;
    for (int i = 0; i <= 1; i++) {
      ok &= (s[1][dif[i]] == s[id][dif[i ^ 1]]);
    }
    return ok;
  } else {
    return (dif.size() == 0 && self_swap);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> k >> n;
  for (int i = 1; i <= k; i++) {
    cin >> s[i];
    s[i] = ' ' + s[i];
  }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      self_swap |= (s[1][i] == s[1][j]);
    }
  for (int i = 2; i <= k; i++)
    for (int j = n; j >= 1; j--)
      if (s[1][j] == s[i][j]) {
        lcp[i][j] = lcp[i][j + 1] + 1;
      }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      swap(s[1][i], s[1][j]);
      bool ok = true;
      for (int id = 2; id <= k; id++) {
        ok &= check(id, i, j);
      }
      if (ok) {
        for (int i = 1; i <= n; i++) {
          cout << s[1][i];
        }
        return 0;
      }
      swap(s[1][i], s[1][j]);
    }
  cout << -1;
  return 0;
}
