#include <bits/stdc++.h>
using namespace std;
const int N = 2507;
string s[N], res;
bool vis[26];
int h[27], n, k, dif[N], tot, nw[N];
bool solve(int p1, int p2) {
  tot = 0;
  for (int i = 0; i < n; i++) {
    if (s[p1][i] != s[p2][i]) {
      dif[tot++] = i;
      nw[i] = 0;
    } else {
      nw[i] = 1;
    }
  }
  if (tot == 1 || tot > 4) {
    return false;
  }
  int ok = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < tot; i++) {
    for (int j = 0; j < n; j++) {
      if (j == dif[i]) continue;
      res = s[p1];
      int fg = 1, t1 = dif[i], t2 = j;
      swap(res[t1], res[t2]);
      for (int now = 0; now < k; now++) {
        if (now != p1) {
          vector<int> vec;
          for (int p = 0; p < n; p++) {
            if (res[p] != s[now][p]) vec.push_back(p);
          }
          if (vec.size() == 1 || vec.size() > 2) {
            fg = 0;
            break;
          } else if (vec.size() == 0) {
            memset(h, 0, sizeof(h));
            int kk = 0;
            for (int z = 0; z < n; z++) {
              int idx = s[now][z] - 'a';
              if (h[idx]) {
                kk = 1;
              }
              h[idx] = 1;
            }
            if (!kk) {
              fg = 0;
              break;
            }
          } else {
            fg &= (res[vec[0]] == s[now][vec[1]] &&
                   res[vec[1]] == s[now][vec[0]]);
            if (!fg) break;
          }
        }
      }
      if (fg) {
        return 1;
      }
    }
  }
  if (!ok) {
    return false;
  }
}
int main() {
  std::ios::sync_with_stdio(false), cin.tie(0);
  cin >> k >> n;
  for (int i = 0; i < k; i++) cin >> s[i];
  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++) {
      if (s[i] != s[j]) {
        int fg1 = solve(i, j);
        if (fg1) {
          return cout << res << endl, 0;
        }
        int fg2 = solve(j, i);
        if (fg2) {
          return cout << res << endl, 0;
        }
        return cout << -1 << endl, 0;
      }
    }
  }
  swap(s[0][0], s[0][1]);
  cout << s[0] << endl;
  return 0;
}
