#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 44;
const int X[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int Y[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int mod = 1e9 + 7;
const long long INF = 1e16;
const int inf = 1e9;
string s[N];
int dif[N], cnt[N], used[N];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> s[i];
  bool ok = 0;
  for (int i = 0; i < m; ++i)
    ok |= (used[s[0][i] - 'a'] ? 1 : 0), ++used[s[0][i] - 'a'];
  for (int i = 1; i < n; ++i) {
    memset(cnt, 0, sizeof(cnt));
    for (int j = 0; j < m; ++j)
      ++cnt[s[i][j] - 'a'], dif[i] += (s[i][j] != s[0][j]);
    for (int j = 0; j < 26; ++j)
      if (cnt[j] != used[j]) return cout << -1, 0;
  }
  int a_ = -1, b_ = -1;
  for (int i = 0; i < m; ++i)
    for (int j = i; j < m; ++j)
      if ((i != j) || (i == j && ok)) {
        bool fl = 1;
        for (int k = 0; k < n; ++k) {
          int diff = dif[k];
          diff -= (s[0][i] != s[k][i]);
          diff -= (s[0][j] != s[k][j]);
          diff += (s[0][i] != s[k][j]);
          diff += (s[0][j] != s[k][i]);
          if (diff > 2 || (!diff && !ok)) fl = 0;
        }
        if (fl) a_ = i, b_ = j;
      }
  if (a_ == -1) return cout << -1, 0;
  swap(s[0][a_], s[0][b_]);
  cout << s[0];
}
