#include <bits/stdc++.h>
using namespace std;
int a[30];
int b[30];
string v[5000];
int how[5000];
int k, n;
bool fuck = false;
inline bool f(int a, int b) {
  for (int i = 1; i < k; ++i) {
    int h = how[i];
    if (v[0][a] != v[0][b]) {
      if (v[0][a] == v[i][a] && v[0][b] != v[i][a]) ++h;
      if (v[0][b] == v[i][b] && v[0][a] != v[i][b]) ++h;
      if (v[0][a] != v[i][a] && v[0][b] == v[i][a]) h--;
      if (v[0][b] != v[i][b] && v[0][a] == v[i][b]) h--;
    }
    if (fuck) {
      if (h > 2) return false;
    } else if (h != 2)
      return false;
  }
  return true;
}
int main() {
  cin >> k >> n;
  cin >> v[0];
  for (auto j : v[0]) {
    b[j - 'a']++;
  }
  for (int i = 0; i < k - 1; ++i) {
    cin >> v[i + 1];
    for (auto j : v[i + 1]) {
      a[j - 'a']++;
    }
    for (int j = 0; j < 30; ++j) {
      if (a[j] != b[j]) {
        cout << -1 << endl;
        return 0;
      }
      if (b[j] > 1) fuck = true;
      a[j] = 0;
    }
  }
  for (int i = 1; i < k; ++i) {
    for (int j = 0; j < n; ++j) {
      if (v[i][j] != v[0][j]) ++how[i];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      if (f(i, j)) {
        swap(v[0][i], v[0][j]);
        cout << v[0] << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
