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;

//.define
//#define FILE_IN_OUT
#define RET(_x)                       return std::cout << (_x), 0;
#define all(_obj)                     (_obj).begin(), (_obj).end()
#define fori(_iterator, _begin, _end) for (int _iterator = (_begin); _iterator < (_end); ++_iterator)
#define forr(_iterator, _begin, _end) for (int _iterator = (_begin); _iterator >= (_end); --_iterator)
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define ceilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define sz(_obj)                      static_cast<int>((_obj).size())
#define endl                          "\n"
template<typename Tp>
inline void outarr(Tp _array, const std::size_t _N, const char* _delim = " ") {
    Tp end = _array + _N;
    for (Tp current = _array; current != end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = __int64;
using pii = std::pair<int, int>;
constexpr int INF = INT_MAX;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
string arr[2501];
int abc[26];
vector<string> cand;

string getType(const string& s) {
    memset(abc, 0, sizeof(abc));
    string res = "";
    loop(sz(s)) {
        ++abc[s[i] - 'a'];
    }
    loop(26) {
        res.append(abc[i], 'a' + i);
    }
    return res;
}

void getCandidates() {
    cand.push_back(arr[0]);
    vector<int> pos;
    loop(sz(arr[0])) {
        if (arr[0][i] != arr[1][i]) {
            pos.push_back(i);
        }
    }
    fori(u, 0, sz(pos)) {
        fori(y, u + 1, sz(pos)) {
            int i = pos[u];
            int j = pos[y];
            char t = arr[0][i];
            arr[0][i] = arr[0][j];
            arr[0][j] = t;
            cand.push_back(arr[0]);
            t = arr[0][i];
            arr[0][i] = arr[0][j];
            arr[0][j] = t;
        }
    }
}

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream сin  ("input.txt",  std::ios::in);
    std::ofstream сout ("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int k, n;
    cin >> k >> n >> arr[0];
    string pattern = getType(arr[0]);
    fori(i, 1, k) {
        cin >> arr[i];
        if (getType(arr[i]) != pattern) {
            RET(-1);
        }
    }

    if (k == 1) {
        char t = arr[0][0];
        arr[0][0] = arr[0][1];
        arr[0][1] = t;
        RET(arr[0]);
    }

    if (arr[1] == arr[0]) {
        bool fl = true;
        fori(i, 2, k) {
            if (arr[i] != arr[0]) {
                string t = arr[1];
                arr[1] = arr[i];
                arr[i] = arr[1];
                fl = false;
                break;
            }
        }
        if (fl) {
            char t = arr[0][0];
            arr[0][0] = arr[0][1];
            arr[0][1] = t;
            RET(arr[0]);
        }
    }

    getCandidates();

    loop(k) {
        fori (t, 0, sz(cand)) {
            int cnt = 0;
            fori(j, 0, n) {
                if (arr[i][j] != cand[t][j]) {
                    ++cnt;
                }
            }
            if (cnt > 2) {
                cand.erase(next(cand.cbegin(), t--));
            }
        }
    }

    if (cand.empty()) {
        RET(-1);
    }

    cout << cand[0];

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}