#include <bits/stdc++.h>
using namespace std;
const long long Llinf = LLONG_MAX;
const int Inf = INT_MAX;
const int Maxn = 5000 + 10;
const int Mod = 1e9 + 7;
const double Pi = acos(-1.0);
char* _c = new char[Maxn];
string GetString() {
  scanf("%s", _c);
  return string(_c);
}
int k, n;
string s[Maxn];
int ham[Maxn];
int ax = -1, ay;
bool f;
vector<int> first(26, 0);
bool is;
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 0; i < k; i++) s[i] = GetString();
  for (int i = 1; i < k; i++)
    for (int j = 0; j < n; j++) ham[i] += (s[0][j] != s[i][j]);
  for (int i = 0; i < n; i++) {
    first[s[0][i] - 'a']++;
    if (first[s[0][i] - 'a'] > 1) is = 1;
  }
  for (int i = 1; i < k; i++) {
    vector<int> second(26, 0);
    for (int j = 0; j < n; j++) second[s[i][j] - 'a']++;
    if (first != second) {
      puts("-1");
      return 0;
    };
  }
  for (int i = 0; i < n && !f; i++) {
    for (int j = i + 1; j < n && !f; j++) {
      swap(s[0][i], s[0][j]);
      f = 1;
      for (int l = 1; l < k; l++) {
        int h = ham[l];
        h -= (s[0][i] == s[l][i]) + (s[0][j] == s[l][j]);
        h += (s[0][i] == s[l][j]) + (s[0][j] == s[l][i]);
        f &= ((h == 0 && is) || h == 2);
      }
      swap(s[0][i], s[0][j]);
      if (f) ax = i, ay = j;
    }
  }
  if (!f)
    printf("-1\n");
  else
    swap(s[0][ax], s[0][ay]), printf("%s\n", s[0].c_str());
  return 0;
}
