#include <bits/stdc++.h>
using namespace std;
string st[5050];
int fr[27];
int main() {
  memset(fr, 0, sizeof(fr));
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> k >> n;
  for (int i = 0; i < k; i++) {
    cin >> st[i];
  }
  string res = st[0];
  memset(fr, 0, sizeof(fr));
  bool du = false;
  for (int i = 0; i < n; i++) {
    fr[res[i] - 'a']++;
    if (fr[res[i] - 'a'] > 1) {
      du = true;
    }
  }
  int ma = 0;
  int mi = 0;
  bool po = true;
  for (int i = 1; i < k; i++) {
    int df = 0;
    int ct[27] = {0};
    for (int j = 0; j < n; j++) {
      ct[st[i][j] - 'a']++;
      if (st[i][j] != res[j]) {
        df++;
      }
    }
    if (df > 4) {
      po = false;
      break;
    }
    for (int j = 0; j < 27; j++) {
      if (ct[j] != fr[j]) {
        po = false;
        break;
      }
    }
    if (df > ma) {
      ma = df;
      mi = i;
    }
  }
  if (!po) {
    cout << -1 << '\n';
    return 0;
  }
  if (ma == 0) {
    swap(res[0], res[1]);
    cout << res << '\n';
    return 0;
  }
  if (ma == 2) {
    if (!du) {
      cout << -1 << '\n';
      return 0;
      cout << -1 << '\n';
      return 0;
    }
    cout << res << '\n';
    return 0;
  }
  int q[4];
  int ctr = 0;
  for (int i = 0; i < n; i++) {
    if (res[i] != st[mi][i]) {
      q[ctr++] = i;
    }
  }
  po = false;
  int tr[2] = {0, 0};
  for (int id = 0; id < 3; id++) {
    if (ma < 4) {
      q[3] = q[id];
    } else if (id > 0)
      break;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (po) break;
        int md = 0;
        swap(res[q[i]], res[q[j]]);
        for (int c = 1; c < k; c++) {
          int df = 0;
          for (int l = 0; l < n; l++) {
            if (res[l] != st[c][l]) {
              df++;
            }
          }
          md = max(md, df);
        }
        swap(res[q[i]], res[q[j]]);
        if (md == 2) {
          po = true;
          tr[0] = i;
          tr[1] = j;
        }
      }
    }
  }
  if (po) {
    swap(res[q[tr[0]]], res[q[tr[1]]]);
    cout << res << '\n';
  } else {
    cout << -1 << '\n';
  }
}
