#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long power(long long a, long long b, long long modi) {
  a %= modi;
  long long res = 1;
  while (b) {
    if (b % 2) {
      res = (res * a) % modi;
    }
    b /= 2;
    a = (a * a) % modi;
  }
  return res;
}
vector<string> vec;
bool match(string s1, string s2) {
  int l = s1.length();
  vector<int> p;
  for (int i = 0; i < l; i++) {
    if (s1[i] != s2[i]) p.push_back(i);
  }
  if ((int)p.size() > 2 || (int)p.size() == 1) return false;
  if (p.empty()) {
    int f[26] = {0};
    for (int i = 0; i < l; i++) f[s1[i] - 'a']++;
    for (int i = 0; i < 26; i++)
      if (f[i] > 1) return true;
    return false;
  }
  if (s1[p[0]] == s2[p[1]] && s1[p[1]] == s2[p[0]]) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int k, n;
    cin >> k >> n;
    string s[k];
    for (int i = 0; i < k; i++) cin >> s[i];
    string ans = "";
    if (k == 1) {
      ans = s[0];
      swap(ans[0], ans[1]);
      cout << ans;
      return 0;
    }
    bool f = false;
    for (int i = 0; i < k; i++) {
      for (int j = i + 1; j < k; j++) {
        int d = 0;
        for (int l = 0; l < n; l++) {
          if (s[i][l] != s[j][l]) d++;
        }
        if (d > 4) {
          f = true;
          break;
        }
      }
      if (f) break;
    }
    if (f) {
      cout << -1;
      return 0;
    }
    vector<int> pos;
    for (int i = 0; i < k; i++) {
      for (int j = i + 1; j < k; j++) {
        for (int l = 0; l < n; l++) {
          if (s[i][l] != s[j][l]) pos.push_back(l);
        }
        if (!pos.empty()) break;
      }
      break;
    }
    if (pos.empty()) {
      ans = s[0];
      swap(ans[0], ans[1]);
      cout << ans;
      return 0;
    }
    for (int i = 0; i < (int)pos.size(); i++) {
      for (int j = 0; j < n; j++) {
        if (pos[i] == j) continue;
        string temp = s[0];
        swap(temp[pos[i]], temp[j]);
        vec.push_back(temp);
      }
    }
    for (int i = 0; i < (int)vec.size(); i++) {
      bool flag = true;
      for (int j = 1; j < k; j++) {
        bool f1 = match(vec[i], s[j]);
        if (!f1) {
          flag = false;
          break;
        }
      }
      if (flag) {
        ans = vec[i];
        break;
      }
    }
    if (ans == "")
      cout << -1;
    else
      cout << ans;
  }
  return 0;
}
