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>
const long long a1 = 31;
const long long a2 = 23;
const long long a3 = 17;
const long long b1 = 100;
const long long b2 = 100;
const long long b3 = 100;
using namespace std;
int n, k;
string s[5000];
bool p1[100], p2[100], p3[100], ptemp[100];
long long pow(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  if (b == 1) return a % mod;
  long long c = pow(a % mod, b / 2, mod);
  if (b & 1) return (long long)((((c * c) % mod) * (a % mod)) % mod);
  return (long long)((c * c) % mod);
}
long long hh(long long e, char c, long long a, long long b) {
  long long cc = (long long)c % b;
  long long pw = pow(a, e, b) % b;
  return (long long)((cc * pw) % b);
}
void generate_hash_pair(string& s, long long a, long long b) {
  long long hp = 0;
  for (int i = 0; i < n; i++) hp = ((hp * a) % b + (long long)s[i]) % b;
  memset(ptemp, 0, sizeof ptemp);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      long long x1 =
          ((-hh(n - i - 1, s[i], a, b) - hh(n - j - 1, s[j], a, b)) % b + b) %
          b;
      long long x2 =
          (hh(n - i - 1, s[j], a, b) + hh(n - j - 1, s[i], a, b)) % b;
      ptemp[(hp + x1 + x2) % b] = 1;
    }
}
void generate_hash_pair(string& s, long long a, long long b, vector<int>& v) {
  long long hp = 0;
  for (int i = 0; i < n; i++) hp = ((hp * a) % b + (long long)s[i]) % b;
  memset(ptemp, 0, sizeof ptemp);
  for (int i = 0; i < n; i++)
    for (int j : v)
      if (j > i) {
        long long x1 =
            ((-hh(n - i - 1, s[i], a, b) - hh(n - j - 1, s[j], a, b)) % b + b) %
            b;
        long long x2 =
            (hh(n - i - 1, s[j], a, b) + hh(n - j - 1, s[i], a, b)) % b;
        ptemp[(hp + x1 + x2) % b] = 1;
      }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> k >> n;
  for (int i = 0; i < k; i++) cin >> s[i];
  memset(p1, -1, sizeof p1);
  memset(p2, -1, sizeof p2);
  memset(p3, -1, sizeof p3);
  if (k > 1)
    for (int i = 0; i < k; i++) {
      vector<int> v;
      for (int j = 0; j < n; j++)
        if (s[i == 0 ? i + 1 : i - 1][j] != s[i][j]) v.push_back(j);
      if (v.size() > 4) {
        cout << -1 << endl;
        return 0;
      }
      if (v.size() <= 0) continue;
      generate_hash_pair(s[i], a1, b1, v);
      for (int i = 0; i < 100; i++) p1[i] = p1[i] && ptemp[i];
      generate_hash_pair(s[i], a2, b2, v);
      for (int i = 0; i < 100; i++) p2[i] = p2[i] && ptemp[i];
      generate_hash_pair(s[i], a3, b3, v);
      for (int i = 0; i < 100; i++) p3[i] = p3[i] && ptemp[i];
    }
  long long hp1 = 0, hp2 = 0, hp3 = 0;
  for (int i = 0; i < n; i++) {
    hp1 = (hp1 * a1) % b1 + (long long)s[0][i];
    hp2 = (hp2 * a2) % b2 + (long long)s[0][i];
    hp3 = (hp3 * a3) % b3 + (long long)s[0][i];
  }
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      long long x1 =
          ((-hh(n - i - 1, s[0][i], a1, b1) - hh(n - j - 1, s[0][j], a1, b1)) %
               b1 +
           b1) %
          b1;
      long long x2 =
          (hh(n - i - 1, s[0][j], a1, b1) + hh(n - j - 1, s[0][i], a1, b1)) %
          b1;
      long long h1 = (hp1 + x1 + x2) % b1;
      x1 = ((-hh(n - i - 1, s[0][i], a2, b2) - hh(n - j - 1, s[0][j], a2, b2)) %
                b2 +
            b2) %
           b2;
      x2 = (hh(n - i - 1, s[0][j], a2, b2) + hh(n - j - 1, s[0][i], a2, b2)) %
           b2;
      long long h2 = (hp2 + x1 + x2) % b2;
      x1 = ((-hh(n - i - 1, s[0][i], a3, b3) - hh(n - j - 1, s[0][j], a3, b3)) %
                b3 +
            b3) %
           b3;
      x2 = (hh(n - i - 1, s[0][j], a3, b3) + hh(n - j - 1, s[0][i], a3, b3)) %
           b3;
      long long h3 = (hp3 + x1 + x2) % b3;
      if (p1[h1] && p2[h2] && p3[h3]) {
        swap(s[0][i], s[0][j]);
        cout << s[0] << endl;
        return 0;
      }
    }
  cout << -1 << endl;
  return 0;
}
