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 FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pi pair<int,int>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pi, null_type,less<pi>, rb_tree_tag,tree_order_statistics_node_update>

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>
#define pi3 pair<int, pi>
#define p4 pair<pi, pi>

const int MX=3000+10;
const ll mod=998244353;

string s[MX], x;
vector<int>mm[MX];
bool dup[MX];

bool ck(int i, int j, int k)
{
    vector<int>v=mm[k], v2;
    bool flg=1, flg2=1;
    for(auto id:mm[k])
    {
        if(id==i) flg=0;
        if(id==j) flg2=0;
    }
    if(flg) v.push_back(i);
    if(flg2) v.push_back(j);

    for(auto id:v)
    {
        if(s[k][id]!=s[0][id]) v2.push_back(id);
    }

    if(v2.size()==0 && dup[k]) return true;
    if(v2.size()==2)
    {
        int p=v2[0], q=v2[1];
        if(x[p]==s[k][q] && x[q]==s[k][p]) return true;
        return false;
    }
    return false;
}

int fr[30];

int main()
{

    FasterIO;


//    int tc; cin>>tc;
//    while(tc--)
    {
        int n, k; cin>>k>>n;
        for(int i=0; i<k; i++)
        {
            cin>>s[i];
            mem(fr, 0);
            for(int j=0; j<n; j++)
            {
                fr[s[i][j]-'a']++;
                if(fr[s[i][j]-'a']==2) dup[i]=1;
            }
        }

        for(int i=1; i<k; i++)
        {
            for(int j=0; j<n; j++)
            {
                if(s[0][j]!=s[i][j]) mm[i].push_back(j);
            }

            if(mm[i].size()>4)
            {
                cout<<-1<<'\n';
                return 0;
            }
        }

        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                bool flg=1;
                swap(s[0][i], s[0][j]);
                for(int l=1; l<k; l++)
                {
                    if(ck(i, j, l));
                    else
                    {
                        flg=0; break;
                    }
                }
                if(flg)
                {
                    cout<<s[0]<<'\n'; return 0;
                }
                swap(s[0][i], s[0][j]);
            }
        }
        cout<<-1<<'\n';
    }
    return 0;
}
