#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long N = 2e5 + 36;
const long long M = 5e3 + 36;
const long long INF = 2e9 + 7;
const long long MOD = 987654323;
const int X[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int Y[8] = {2, -2, 2, -2, 1, -1, 1, -1};
string s[M], c[M];
int mk[M];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i(0); i < n; ++i) {
    cin >> s[i];
    c[i] = s[i];
    sort(c[i].begin(), c[i].end());
  }
  bool HH = false;
  for (int i(0); i < m; ++i) {
    mk[s[0][i]]++;
    if (mk[s[0][i]] > 1) {
      HH = true;
    }
  }
  for (int i(1); i < n; ++i) {
    if (c[0] != c[i]) {
      cout << -1 << '\n';
      return 0;
    }
  }
  random_shuffle(s, s + n);
  for (int i(0); i < m; ++i) {
    if (clock() * 1.0 / CLOCKS_PER_SEC > 0.90) {
      break;
    }
    for (int j(i + 1); j < m; ++j) {
      swap(s[0][i], s[0][j]);
      bool first = true;
      for (int i(1); i < n; ++i) {
        int k = 0;
        for (int j(0); j < m; ++j) {
          if (s[0][j] != s[i][j]) {
            k++;
            if (k > 2) break;
          }
        }
        if ((k != 0 && k != 2) || (k == 0 && HH == false)) {
          first = false;
          break;
        }
      }
      if (first) {
        cout << s[0] << '\n';
        return 0;
      }
      swap(s[0][i], s[0][j]);
    }
  }
  cout << -1 << '\n';
  return 0;
}
