#include <bits/stdc++.h>
using namespace std;
int k, n;
string s[2500];
int diffWith[2500];
bool isDouble = false;
bool notSameCharacters() {
  int occurences[26];
  int occurences2[26];
  memset(occurences, 0, 26 * sizeof(int));
  for (int i = 0; i < (n); i++) occurences[s[0][i] - 'a']++;
  for (int i = (1); i < (k); i++) {
    memset(occurences2, 0, 26 * sizeof(int));
    for (int j = 0; j < (n); j++) occurences2[s[i][j] - 'a']++;
    for (int j = 0; j < (26); j++)
      if (occurences2[j] != occurences[j]) return true;
  }
  return false;
}
void checkForDouble() {
  set<char> se;
  for (const char c : s[0]) {
    if (se.count(c)) {
      isDouble = true;
      return;
    } else {
      se.insert(c);
    }
  }
}
bool works(int p1, int p2) {
  for (int i = (1); i < (k); i++) {
    int differeces = diffWith[i];
    if (s[0][p1] != s[i][p1]) differeces--;
    if (s[0][p2] != s[i][p2]) differeces--;
    if (s[0][p1] != s[i][p2]) differeces++;
    if (s[0][p2] != s[i][p1]) differeces++;
    if (!isDouble && differeces == 0) return false;
    if (differeces > 2) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> k >> n;
  for (int i = 0; i < (k); i++) {
    cin >> s[i];
    for (int j = 0; j < (n); j++)
      if (s[0][j] != s[i][j]) diffWith[i]++;
  }
  if (notSameCharacters()) {
    cout << -1 << endl;
    return false;
  }
  checkForDouble();
  for (int i = 0; i < (n); i++)
    for (int j = (i + 1); j < (n); j++) {
      if (works(i, j)) {
        swap(s[0][i], s[0][j]);
        cout << s[0] << endl;
        return 0;
      }
    }
  cout << -1 << endl;
  return 0;
}
