#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int k, n;
vector<int> diff(int a, int b) {
  vector<int> ret;
  for (int i = 0; i < n; i++) {
    if (v[a][i] != v[b][i]) {
      ret.push_back(i);
    }
  }
  return ret;
}
bool hel(string& s) {
  vector<int> freq(26, 0);
  for (char c : s) {
    freq[c - 'a']++;
    if (freq[c - 'a'] > 1) return true;
  }
  return false;
}
bool test() {
  for (int p = 1; p < k; p++) {
    vector<int> d = diff(0, p);
    if (d.size() == 0 && hel(v[p])) continue;
    if (d.size() == 2) continue;
    return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> k >> n;
  v = vector<string>(k);
  for (int i = 0; i < k; i++) cin >> v[i];
  vector<string> u = v;
  for (int i = 0; i < k; i++) {
    sort(u[i].begin(), u[i].end());
  }
  for (int i = 1; i < k; i++) {
    if (u[i] != u[i - 1]) {
      cout << -1;
      return 0;
    }
  }
  bool neq = false;
  for (int i = 1; !neq && i < k; i++) {
    if (v[i] != v[0]) neq = true;
  }
  if (k == 1 || !neq) {
    if (n == 1) {
      cout << -1;
      return 0;
    } else {
      swap(v[0][0], v[0][1]);
      cout << v[0];
      return 0;
    }
  }
  bool ok = true;
  for (int p = 1; ok && p < k; p++) {
    vector<int> d = diff(0, p);
    if (d.size() > 4) {
      ok = false;
    } else if (d.size() > 0) {
      for (int i = 0; i < n; i++) {
        for (int j : d) {
          if (i == j) continue;
          swap(v[0][i], v[0][j]);
          if (test()) {
            cout << v[0];
            return 0;
          }
          swap(v[0][i], v[0][j]);
        }
      }
    }
  }
  cout << -1;
  return 0;
}
