#include <bits/stdc++.h>
using namespace std;
const int N = 2500 + 10;
int k, n;
vector<int> pos;
string s[N];
bool check(string t) {
  for (int i = 0; i < k; i++) {
    bool ok = 1;
    int cnt = 0, pos1 = -1, pos2 = -1;
    for (int j = 0; j < n; j++)
      if (s[i][j] != t[j]) {
        cnt++;
        if (pos1 == -1)
          pos1 = j;
        else if (pos2 == -1)
          pos2 = j;
      }
    if (cnt != 0 && cnt != 2) return false;
    if (cnt == 2 && (s[i][pos1] != t[pos2] || s[i][pos2] != t[pos1]))
      return false;
    if (cnt != 0 || n > 26) ok = 0;
    if (!ok) continue;
    int vis[26];
    memset(vis, 0, sizeof(vis));
    for (int j = 0; j < n && ok; j++) {
      vis[s[i][j] - 'a']++;
      if (vis[s[i][j] - 'a'] > 1) ok = 0;
    }
    if (ok) return false;
  }
  return true;
}
int main() {
  scanf("%d %d", &k, &n);
  for (int i = 0; i < k; i++) cin >> s[i];
  bool same = 1;
  int diff = 0;
  for (int i = 1; i < k && same; i++)
    for (int j = 0; j < n && same; j++)
      if (s[0][j] != s[i][j]) same = 0, diff = i;
  if (same) {
    swap(s[0][0], s[0][1]);
    cout << s[0] << endl;
  } else {
    for (int i = 0; i < n; i++)
      if (s[0][i] != s[diff][i]) pos.push_back(i);
    int sz = pos.size();
    if (sz > 4)
      puts("-1");
    else {
      bool ans = 0;
      for (int i = 0; i < sz && !ans; i++) {
        for (int j = 0; j < n; j++) {
          if (j == pos[i]) continue;
          string s1 = s[0], s2 = s[diff];
          swap(s1[pos[i]], s1[j]);
          if (check(s1)) {
            cout << s1 << endl;
            ans = 1;
            break;
          }
          swap(s2[pos[i]], s2[j]);
          if (check(s2)) {
            cout << s2 << endl;
            ans = 1;
            break;
          }
        }
      }
      if (!ans) puts("-1");
    }
  }
  return 0;
}
