#include <bits/stdc++.h>
using namespace std;
void fail() {
  cout << -1 << endl;
  exit(0);
}
int main() {
  int K, N;
  cin >> K >> N;
  set<string> st;
  for (int i = 0; i < K; i++) {
    string s;
    cin >> s;
    st.insert(s);
  }
  vector<string> S;
  for (auto& s : st) S.push_back(s);
  K = S.size();
  string sorted = S[0];
  sort(sorted.begin(), sorted.end());
  for (auto s : S) {
    sort(s.begin(), s.end());
    if (sorted != s) fail();
  }
  map<char, int> cnt;
  for (char c : S[0]) cnt[c]++;
  bool dub = false;
  for (auto& p : cnt)
    if (p.second > 1) dub = true;
  if (K == 1) {
    string ans = S[0];
    swap(ans[0], ans[1]);
    cout << ans << endl;
    return 0;
  }
  vector<int> D;
  for (int i = 0; i < N; i++)
    if (S[0][i] != S[1][i]) D.push_back(i);
  int sz = D.size();
  if (sz > 4) fail();
  auto check = [&](string& s) {
    for (auto& t : S) {
      int num = 0;
      for (int i = 0; i < N; i++)
        if (s[i] != t[i]) num++;
      if (num == 2 || (dub && num == 0)) {
      } else {
        return;
      }
    }
    cout << s << endl;
    exit(0);
  };
  check(S[0]);
  for (int i = 0; i < N; i++)
    for (int j : D)
      if (i != j) {
        string ans = S[0];
        swap(ans[i], ans[j]);
        check(ans);
      }
  fail();
  return 0;
}
