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 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;
}
