#include <bits/stdc++.h>
using namespace std;
inline int input() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
string s[maxn];
short val[2501][5001];
int dif[2501];
bool identical[2501];
bool mark[26];
int cnt[26];
int32_t main() {
  int k = in(), n = in();
  for (int i = 0; i < k; i++) {
    cin >> s[i];
    for (int j = 0; j < 26; j++) mark[j] = false;
    for (int j = 0; j < n; j++) {
      val[i][j] = s[i][j] - 'a';
      if (mark[val[i][j]]) identical[i] = true;
      mark[val[i][j]] = true;
    }
  }
  for (int i = 1; i < k; i++) {
    for (int pt = 0; pt < n; pt++) cnt[val[0][pt]]++;
    for (int pt = 0; pt < n; pt++) {
      cnt[val[i][pt]]--;
      if (cnt[val[i][pt]] < 0) return cout << -1 << endl, 0;
    }
  }
  for (int i = 1; i < k; i++)
    for (int j = 0; j < n; j++) dif[i] += val[i][j] != val[0][j];
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      swap(val[0][i], val[0][j]);
      int maxi = 0;
      bool fl = true;
      for (int pt = 1; pt < k; pt++) {
        dif[pt] -= val[0][i] == val[pt][i] && val[0][j] != val[pt][i];
        dif[pt] -= val[0][j] == val[pt][j] && val[0][i] != val[pt][j];
        dif[pt] += val[0][j] == val[pt][i] && val[0][i] != val[pt][i];
        dif[pt] += val[0][i] == val[pt][j] && val[0][j] != val[pt][j];
        maxi = max(maxi, dif[pt]);
        fl &= dif[pt] != 1;
        if (dif[pt] == 0) fl &= identical[pt];
        dif[pt] += val[0][i] == val[pt][i] && val[0][j] != val[pt][i];
        dif[pt] += val[0][j] == val[pt][j] && val[0][i] != val[pt][j];
        dif[pt] -= val[0][j] == val[pt][i] && val[0][i] != val[pt][i];
        dif[pt] -= val[0][i] == val[pt][j] && val[0][j] != val[pt][j];
      }
      if (maxi <= 2 && fl) {
        swap(s[0][i], s[0][j]);
        cout << s[0] << endl;
        return 0;
      }
      swap(val[0][i], val[0][j]);
    }
  }
  cout << -1 << "\n";
}
