3 4
kbub
kbbu
ubkb
 5 5
zbibx
zbbix
zbibx
xbibz
xbibz
 100 2
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
qz
 100 3
zsk
zsk
zsk
zsk
skz
skz
kzs
skz
kzs
kzs
zsk
kzs
kzs
kzs
skz
kzs
skz
skz
kzs
zsk
kzs
kzs
kzs
skz
skz
skz
zsk
skz
zsk
skz
kzs
skz
skz
skz
kzs
zsk
zsk
kzs
skz
skz
kzs
kzs
skz
kzs
kzs
skz
kzs
skz
kzs
kzs
skz
kzs
kzs
kzs
kzs
skz
kzs
skz
skz
skz
skz
zsk
kzs
skz
zsk
kzs
skz
skz
skz
kzs
kzs
skz
skz
kzs
kzs
skz
zsk
skz
zsk
kzs
kzs
skz
kzs
kzs
kzs
zsk
kzs
kzs
zsk
kzs
skz
zsk
skz
skz
skz
kzs
zsk
kzs
kzs
skz
 5 5
eellh
ehlle
ehlle
helle
hlele
 2 3
ghn
ghn
 2 4
ayax
abac
 2 6
abcdef
badcef
 1 2
yu
 2 4
ajax
azad
 2 2
nm
nm
 2 2
ac
ca
 5 5
gyvnn
gnvny
vygnn
gynvn
gnvny
 2 2
ab
cd
 3 3
uvh
vhu
huv
 3 2
xh
xh
xh
 3 2
cg
cg
cg
 8 23
mgiomcytqdvoihhcirldmuj
mgmoicytqdvoihhicrldmuj
mgmomcytqdvoihhicrldiuj
mgcomcytqdvoihhiirldmuj
mgiimcytqdvoihhocrldmuj
mgioicytqdvoihhmcrldmuj
mgiomcytqdvodhhicrlimuj
mgiomcytjdvoihhicrldmuq
 8 6
mnionk
mnikno
inmkno
mnnkio
oniknm
oniknm
mkinno
mnikon
 1 3
vts
 2 3
abc
abz
 2 4
abcd
ccdc
 2 5
dbcag
acbdh
 2 16
hmlqgaepsgpdbzyk
chhhburuvnyirrim

kbub
 zbibx
 zq
 szk
 helle
 hgn
 -1
 bacdef
 uy
 -1
 mn
 -1
 gyvnn
 -1
 vuh
 hx
 gc
 mgiomcytqdvoihhicrldmuj
 mnikno
 tvs
 -1
 -1
 -1
 -1

#include <bits/stdc++.h>
using namespace std;
const int LIM = 5009;
const long long MOD = 1000000007LL;
int k, n;
string s[LIM], res = " ";
int f[LIM][26];
vector<vector<int> > _hash;
long long addM(long long A, long long B) { return (A + B) % MOD; }
long long subM(long long A, long long B) { return (MOD + (A - B) % MOD) % MOD; }
long long mulM(long long A, long long B) { return (A * B) % MOD; }
long long powM(long long bs, long long pwr) {
  long long func = 1LL;
  int bfst = 64 - __builtin_clzll(pwr);
  for (int i = bfst - 1; i >= 0; i--) {
    func = mulM(func, func);
    if (pwr & (1LL << i)) func = mulM(func, bs);
  }
  return func;
}
bool first_check() {
  string _s1 = s[1];
  sort(_s1.begin(), _s1.end());
  for (int i = 2; i <= k; i++) {
    string _s = s[i];
    sort(_s.begin(), _s.end());
    if (_s != _s1) return false;
  }
  return true;
}
void init() {
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= n; j++) f[j][s[i][j] - 'a']++;
  for (int i = 1; i <= n; i++) {
    res += "-";
    for (int j = 0; j < 26; j++)
      if (f[i][j] >= k - 1) {
        res[i] = 'a' + j;
        break;
      }
  }
}
void print_swap(int ci, int cj) {
  for (int ii = 1; ii <= n; ii++) {
    if (ii == cj)
      cout << s[0][ci];
    else if (ii == ci)
      cout << s[0][cj];
    else
      cout << s[0][ii];
  }
  cout << "\n";
}
long long get_hash(int id, int x, int y, int changed_i, int changed_j) {
  long long delta_1x = 0, delta_1y = 0, delta_2x = 0, delta_2y = 0;
  if (changed_j < 1 || y < changed_i) {
  } else {
    if (changed_i < x) {
      delta_1x = mulM(powM(27LL, x - 1 - changed_i),
                      (s[id][changed_j] - s[id][changed_i]));
    }
    if (changed_i <= y) {
      delta_1y = mulM(powM(27LL, y - changed_i),
                      (s[id][changed_j] - s[id][changed_i]));
    }
    if (changed_j < x) {
      delta_2x = mulM(powM(27LL, x - 1 - changed_j),
                      (s[id][changed_i] - s[id][changed_j]));
    }
    if (changed_j <= y) {
      delta_2y = mulM(powM(27LL, y - changed_j),
                      (s[id][changed_i] - s[id][changed_j]));
    }
  }
  long long res = subM((_hash[id][y] + delta_1y + delta_2y) % MOD,
                       mulM((_hash[id][x - 1] + delta_1x + delta_2x) % MOD,
                            powM(27LL, y - x + 1)));
  return res;
}
int find_id(int id, int x, int y, int ci, int cj) {
  int lt = x, rt = y;
  for (int buuluu = 0; buuluu < 64; buuluu++) {
    if (lt > rt)
      return -1;
    else if (lt == rt) {
      if (get_hash(0, x, lt - 1, ci, cj) == get_hash(id, x, lt - 1, 0, 0) &&
          get_hash(0, x, lt, ci, cj) != get_hash(id, x, lt, 0, 0))
        return lt;
      else
        return -1;
    } else if (rt - lt == 1) {
      if (get_hash(0, x, rt - 1, ci, cj) == get_hash(id, x, rt - 1, 0, 0) &&
          get_hash(0, x, rt, ci, cj) != get_hash(id, x, rt, 0, 0))
        return rt;
      else if (get_hash(0, x, lt - 1, ci, cj) ==
                   get_hash(id, x, lt - 1, 0, 0) &&
               get_hash(0, x, lt, ci, cj) != get_hash(id, x, lt, 0, 0))
        return lt;
      else
        return -1;
    }
    int mid = (lt + rt) / 2;
    if (get_hash(0, x, mid, ci, cj) == get_hash(id, x, mid, 0, 0))
      lt = mid;
    else {
      if (get_hash(0, x, mid - 1, ci, cj) == get_hash(id, x, mid - 1, 0, 0))
        return mid;
      else
        rt = mid;
    }
  }
  return -1;
}
bool check(int ci, int cj) {
  for (int i = 1; i <= k; i++) {
    if (get_hash(0, 1, n, ci, cj) == get_hash(i, 1, n, 0, 0)) continue;
    int i1 = find_id(i, 1, n, ci, cj);
    if (i1 == -1) return false;
    int i2 = find_id(i, i1 + 1, n, ci, cj);
    if (i2 == -1) return false;
    if (get_hash(0, i2 + 1, n, ci, cj) != get_hash(i, i2 + 1, n, 0, 0))
      return false;
  }
  return true;
}
void re_hash(int i) {
  _hash[i].assign(n + 1, 0);
  for (int j = 1; j <= n; j++)
    _hash[i][j] = (_hash[i][j - 1] * 27LL + (s[i][j] - 'a' + 1)) % MOD;
}
int main() {
  cin >> k >> n;
  _hash.assign(k + 1, vector<int>());
  for (int i = 1; i <= k; i++) {
    cin >> s[i];
    s[i] = " " + s[i];
    re_hash(i);
  }
  if (!first_check()) {
    cout << "-1\n";
    return 0;
  }
  s[0] = s[1];
  re_hash(0);
  init();
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      if (res[i] == '-' && res[j] == '-') {
        if (check(i, j)) {
          print_swap(i, j);
          return 0;
        }
      }
  cout << "-1\n";
}
