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;
long long MP[5555];
bool can[2555][5555];
string Solve(const vector<string>& Svec) {
  int n = Svec.size();
  if (Svec.size() == 1) {
    string ans = Svec[0];
    swap(ans[0], ans[1]);
    return ans;
  }
  int L = Svec[0].size();
  MP[0] = 1;
  for (int i = 1; i <= L; i++) MP[i] = (MP[i - 1] * 30) % 1000000000039ll;
  map<char, int> exp_counts;
  for (int i = 0; i < L; i++) {
    exp_counts[Svec[0][i]]++;
  }
  for (int sid = 1; sid < n; ++sid) {
    map<char, int> counts;
    int ct = 0;
    for (int i = 0; i < L; i++) {
      if (Svec[sid][i] != Svec[0][i]) ct++;
      counts[Svec[sid][i]]++;
    }
    if (ct > 4 || counts != exp_counts) return "-1";
  }
  for (int sid = 0; sid < n; ++sid) {
    for (int i = 0; i < L; i++) {
      can[sid][i] = false;
      for (int s2 = 0; s2 < n; s2++) {
        if (Svec[sid][i] != Svec[s2][i]) {
          can[sid][i] = true;
          break;
        }
      }
    }
  }
  long long hashvals[2555];
  unordered_map<long long, int> counts;
  for (int sid = 0; sid < Svec.size(); ++sid) {
    const string& S = Svec[sid];
    hashvals[sid] = 0;
    for (int j = L - 1; j >= 0; j--) {
      hashvals[sid] = (hashvals[sid] * 30 + S[j] - 'a') % 1000000000039ll;
    }
    unordered_set<long long> unique_hashes;
    long long hashval = hashvals[sid];
    for (int i = 0; i < L; i++) {
      if (!can[sid][i]) continue;
      for (int j = 0; j < L; j++) {
        if (i == j) continue;
        long long currhash = hashval - (S[i] - S[j]) * (MP[i] - MP[j]);
        currhash %= 1000000000039ll;
        if (currhash < 0) currhash += 1000000000039ll;
        if (sid == 0 || counts.find(currhash) != counts.end()) {
          unique_hashes.insert(currhash);
        }
      }
    }
    for (long long x : unique_hashes) counts[x]++;
  }
  long long ans = -1;
  for (auto x : counts) {
    if (x.second == n) {
      ans = x.first;
    }
  }
  if (ans == -1) return "-1";
  for (int sid = 0; sid < Svec.size(); ++sid) {
    const string& S = Svec[sid];
    long long hashval = hashvals[sid];
    for (int i = 0; i < L; i++) {
      if (!can[sid][i]) continue;
      for (int j = 0; j < L; j++) {
        if (i == j) continue;
        long long currhash = hashval - (S[i] - S[j]) * (MP[i] - MP[j]);
        currhash %= 1000000000039ll;
        if (currhash < 0) currhash += 1000000000039ll;
        if (currhash == ans) {
          string ret = S;
          swap(ret[i], ret[j]);
          return ret;
        }
      }
    }
  }
  return "-1";
}
int main() {
  int k, n;
  cin >> k >> n;
  std::set<string> unique_S;
  for (int i = 0; i < k; i++) {
    string S;
    cin >> S;
    unique_S.insert(S);
  }
  vector<string> Svec(unique_S.begin(), unique_S.end());
  cout << Solve(Svec) << endl;
}
