#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5, mod = 1e9 + 7;
string s[N];
int k, n, rep = 0, h[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> k >> n;
  for (int i = 0; i < k; i++) cin >> s[i];
  vector<int> f(26);
  for (int i = 0; i < n; i++)
    f[s[0][i] - 'a']++, rep |= ((f[s[0][i] - 'a']) > 1);
  bool flag = true;
  for (int i = 1; i < k; i++) {
    vector<int> g(26);
    for (int j = 0; j < n; j++) g[s[i][j] - 'a']++;
    if (f != g) flag = false;
  }
  if (!flag) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i < k; i++)
    for (int j = 0; j < n; j++) h[i] += (s[0][j] != s[i][j]);
  int x = -1, y = -1;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      bool flag = true;
      for (int p = 1; p < k; p++) {
        int cnt = h[p];
        if (s[0][i] == s[p][i]) cnt++;
        if (s[0][j] == s[p][j]) cnt++;
        if (s[0][i] == s[p][j]) cnt--;
        if (s[0][j] == s[p][i]) cnt--;
        if (!((rep && cnt == 0) || cnt == 2)) flag = false;
      }
      if (flag) x = i, y = j;
    }
  }
  if (x == -1)
    puts("-1");
  else
    swap(s[0][x], s[0][y]), cout << s[0] << endl;
  return 0;
}
