#include <bits/stdc++.h>
using namespace std;
string s[5000];
int n, k;
bool test(string T) {
  int cnt[26];
  for (int i = 0; i < n; ++i) {
    fill(cnt, cnt + 26, 0);
    vector<int> diff;
    for (int j = 0; j < k; ++j) {
      ++cnt[s[i][j] - 'a'];
      if (s[i][j] != T[j]) diff.push_back(j);
    }
    if (s[i] == T) {
      if (count_if(cnt, cnt + 26, [](int a) { return a > 1; }) == 0)
        return false;
    } else {
      if (diff.size() != 2) return false;
      swap(T[diff[0]], T[diff[1]]);
      if (s[i] != T) return false;
      swap(T[diff[0]], T[diff[1]]);
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 1; i < n; ++i) {
    if (s[i] != s[i - 1]) {
      int diff_cnt = 0;
      for (int j = 0; j < k; ++j) {
        diff_cnt += s[i][j] != s[i - 1][j];
      }
      if (diff_cnt > 4) {
        cout << -1 << '\n';
        return 0;
      }
      for (int j = 0; j < k; ++j) {
        if (s[i][j] != s[i - 1][j]) {
          for (int l = 0; l < k; ++l) {
            if (l == j) continue;
            string T = s[i];
            swap(T[j], T[l]);
            if (test(T)) {
              cout << T << '\n';
              return 0;
            }
            T = s[i - 1];
            swap(T[j], T[l]);
            if (test(T)) {
              cout << T << '\n';
              return 0;
            }
          }
        }
      }
      cout << -1 << '\n';
      return 0;
    }
  }
  swap(s[0][0], s[0][1]);
  cout << s[0] << '\n';
}
