#include <bits/stdc++.h>
using namespace std;
const int maxk = 2500 + 11;
const int maxn = 5e3 + 11;
int k, n;
vector<string> vec;
int diff[maxk][maxn];
void build() {
  for (int i = 1; i < k; i++) {
    for (int j = 0; j < n; j++) diff[i][j] = vec[i][j] != vec[0][j];
    partial_sum(diff[i], diff[i] + n, diff[i]);
  }
}
int query(int* arr, int l, int r) {
  if (r < l) return 0;
  if (l == 0) return arr[r];
  return arr[r] - arr[l - 1];
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> k >> n;
  vec.resize(k);
  for (int i = 0; i < k; i++) cin >> vec[i];
  build();
  bool id = false;
  string srt = vec[0];
  sort(srt.begin(), srt.end());
  for (int i = 1; i < n; i++) id |= srt[i] == srt[i - 1];
  for (int i = 1; i < k; i++) {
    string cmp = vec[i];
    sort(cmp.begin(), cmp.end());
    if (srt != cmp) {
      return 0 * puts("-1");
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      bool ok = true;
      for (int m = 1; m < k; m++) {
        int temp = 0;
        temp += query(diff[m], 0, i - 1);
        temp += query(diff[m], i + 1, j - 1);
        temp += query(diff[m], j + 1, n - 1);
        temp += vec[m][i] != vec[0][j];
        temp += vec[m][j] != vec[0][i];
        if (id)
          ok &= temp <= 2;
        else
          ok &= temp == 2;
      }
      if (ok) {
        swap(vec[0][i], vec[0][j]);
        cout << vec[0] << endl;
        return 0;
      }
    }
  cout << -1 << endl;
  return 0;
}
