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

// 2017-12-12 17:58:24
#include <bits/stdc++.h>
using namespace std;
// misc {{{
using u64 = uint64_t;
using u32 = uint32_t;
using i64 = int64_t;
using i32 = int32_t;
const i64 inf = (1ll << 62);
const i64 imax = std::numeric_limits<i64>::max();
const i64 umax = std::numeric_limits<u64>::max();
void merror(std::string msg, i64 line_number) { std::cerr << "assert >> " << line_number << ": " << msg << std::endl; exit(42); }
#ifndef NDEBUG
#define massert(c, msg) do { if (!(c)) merror(msg, __LINE__); } while(0)
#define massert2(c) massert(c, "")
#else
#define massert(...)
#define massert2(...)
#endif
template <typename C> i64 isize(const C& c) { return static_cast<i64>(c.size()); }
template <typename T, size_t N> i64 isize(const std::array<T, N>& = {}) { return static_cast<i64>(N); }
template <typename It, typename Cont> bool it_last(It it, const Cont& c) { return ++it == c.cend(); }
// }}}
// functors {{{
namespace fun {
template <typename T> const auto identity = [](const T& t) -> const T& { return t; };
template <typename T> const auto first = [](const T& t) { return t.first; };
template <typename T> const auto second = [](const T& t) { return t.second; };
template <typename T, u32 n> const auto nth = [](const T& t) { return std::get<n>(t); };
template <typename TOut, typename F, typename TIn> std::vector<TOut> transf(const TIn& in, F f) { std::vector<TOut> v; transform(in.begin(), in.end(), back_inserter(v), f); return v; }
template <typename F, typename T> void sort(T& v, F f) { std::sort(v.begin(), v.end(), f); }
template <typename TOut, typename F, typename TIn> std::vector<TOut> sorted(const TIn& in, F f) { std::vector<TOut> v(in.begin(), in.end()); sort(v, f); return v; }
} // fun
// }}}
// class traits {{{
template<class...> using void_t = void;
template <class, class = void> struct has_repr : std::false_type {};
template <class T> struct has_repr<T, void_t<decltype(std::declval<T>()._repr())>> : std::true_type {};
template <class, class = void> struct has_str : std::false_type {};
template <class T> struct has_str<T, void_t<decltype(std::declval<T>()._str())>> : std::true_type {};
template <class, class = void> struct has_read : std::false_type {};
template <class T> struct has_read<T, void_t<decltype(std::declval<T>()._read())>> : std::true_type {};
template <class, class = void> struct is_map : std::false_type {};
template <class T> struct is_map<T, void_t<typename T::key_type, typename T::mapped_type>> : std::true_type {};
template <class, class = void> struct is_set : std::false_type {};
template <class T> struct is_set<T, void_t<typename T::key_type>> : std::true_type {};
// }}}
// str {{{
template <typename T, class = void> struct _Str { std::string operator()(const T& t) { return std::to_string(t); } };
template <> struct _Str<std::string> { std::string operator()(const std::string& t) { return t; } };
template <> struct _Str<const char*> { std::string operator()(const char* t) { return t; } };
template <typename T> std::string str(const T& t) { return _Str<T>()(t); }
template <typename T> struct _Str<T, std::enable_if_t<has_str<T>::value>> { std::string operator()(const T& t) {
    return t._str();
} };
template <typename T>
struct _Str<std::vector<T>> {
    std::string operator()(const std::vector<T>& t) {
        std::string s = "";
        for (i64 i = 0; i < isize(t); i++) {
            s += str(t[i]);
            if (i != isize(t) - 1)
                s += ' ';
        }
        return s;
    }
};
// }}}
// string tuples {{{
template <i32 rev_index, typename T> struct _StrTuple { std::string operator() (const T& tpl) {
    return str(std::get<std::tuple_size<T>::value - rev_index>(tpl)) + ' ' + _StrTuple<rev_index - 1, T>()(tpl);
} };
template <typename T> struct _StrTuple<1, T> { std::string operator()(const T& t) {
    return str(std::get<std::tuple_size<T>::value - 1>(t));
} };
template <> struct _StrTuple<0, std::tuple<>> { std::string operator()(const std::tuple<>&) { return ""; } };
template <typename ...Ts> struct _Str<std::tuple<Ts...>> { std::string operator()(const std::tuple<Ts...>& t) {
    using T = std::tuple<Ts...>;
    return _StrTuple<std::tuple_size<T>::value, T>()(t);
} };
template <class T1, class T2> struct _Str<std::pair<T1, T2>> { std::string operator()(const std::pair<T1, T2>& p) {
    return str(make_tuple(p.first, p.second));
} };
// }}}
// repr {{{
template <typename T, class = void> struct _Repr { std::string operator()(const T& t) { return str(t); } };
template <typename T> std::string repr(const T& t) { return _Repr<T>()(t); }
template <> struct _Repr<std::string> { std::string operator()(const std::string& t) { return '"' + t + '"'; } };
template <> struct _Repr<const char*> { std::string operator()(const char* const& t) { return repr(std::string(t)); } };
template <typename T> struct _Repr<T, std::enable_if_t<has_repr<T>::value>> { std::string operator()(const T& t) {
    return t._repr();
} };
template <typename T>
struct _Repr<std::vector<T>> {
    std::string operator()(const std::vector<T>& t) {
        std::string s = "[";
        for (i64 i = 0; i < isize(t); i++) {
            s += repr(t[i]);
            if (i != isize(t) - 1)
                s += ',';
        }
        s += ']';
        return s;
    }
};
template <typename T>
struct _Repr<T, std::enable_if_t<is_set<T>::value && !is_map<T>::value>> {
    std::string operator()(const T& t) {
        std::string s = "{";
        for (auto it = t.cbegin(); it != t.cend(); it++) {
            s += repr(*it);
            if (!it_last(it, t))
                s += ',';
        }
        s += '}';
        return s;
    }
};
template <typename T>
struct _Repr<T, std::enable_if_t<is_map<T>::value>> {
    std::string operator()(const T& t) {
        std::string s = "{";
        for (auto it = t.cbegin(); it != t.cend(); it++) {
            s += repr(it->first) + ':' + repr(it->second);
            if (!it_last(it, t))
                s += ',';
        }
        s += '}';
        return s;
    }
};
// }}}
// struct repr helpers {{{
std::string _repr_helper(i64 i, const std::vector<std::string>& header) {
    massert(i == isize(header), "header too long");
    return "";
}
template <typename T, typename ...Ts>
std::string _repr_helper(i64 i, const std::vector<std::string>& header, const T& t, const Ts&... ts) {
    massert(i < isize(header), "header too short");
    auto s = header[i] + "=" + repr(t);
    if (i < isize(header) - 1)
        s += "," + _repr_helper(i + 1, header, ts...);
    return s;
}
template <typename ...Ts>
std::string make_repr(std::string classname, const std::vector<std::string>& header, const Ts&... ts) {
    return classname + '(' + _repr_helper(0, header, ts...) + ')';
}
/// }}}
// repring tuples {{{
template <i32 rev_index, typename T> struct _ReprTuple { std::string operator() (const T& tpl) {
    return repr(std::get<std::tuple_size<T>::value - rev_index>(tpl)) + ',' + _ReprTuple<rev_index - 1, T>()(tpl);
} };
template <typename T> struct _ReprTuple<1, T> { std::string operator()(const T& t) {
    return repr(std::get<std::tuple_size<T>::value - 1>(t));
} };
template <> struct _ReprTuple<0, std::tuple<>> { std::string operator()(const std::tuple<>&) { return ""; } };
template <typename ...Ts> struct _Repr<std::tuple<Ts...>> { std::string operator()(const std::tuple<Ts...>& t) {
    using T = std::tuple<Ts...>;
    return '(' + _ReprTuple<std::tuple_size<T>::value, T>()(t) + ')';
} };
template <class T1, class T2> struct _Repr<std::pair<T1, T2>> { std::string operator()(const std::pair<T1, T2>& p) {
    return repr(make_tuple(p.first, p.second));
} };
// }}}
// print containers {{{
template <typename It> void _print_collection(std::ostream& os, It begin, It end) { os << "["; while (begin != end) { os << *(begin++); if (begin != end) os << ','; } os << "]"; }
#define MAKE_PRINTER_1(container) template <typename T> std::ostream& operator<<(std::ostream& os, const container<T>& t) { _print_collection(os, t.begin(), t.end()); return os; }
#define MAKE_PRINTER_2(container) template <typename T1, typename T2> std::ostream& operator<<(std::ostream& os, const container<T1, T2>& t) { _print_collection(os, t.begin(), t.end()); return os; }
MAKE_PRINTER_1(std::vector)
MAKE_PRINTER_2(std::map)
MAKE_PRINTER_1(std::set)
MAKE_PRINTER_2(std::unordered_map)
MAKE_PRINTER_1(std::unordered_set)
#undef MAKE_PRINTER_1
#undef MAKE_PRINTER_2
// }}}
// read/write {{{
template <typename T, std::enable_if_t<!has_read<T>::value, int> = 0> T read() { T e; std::cin >> e; return e; }
template <typename T, std::enable_if_t<has_read<T>::value, int> = 0> T read() { T t; t._read(); return t; }
void read() {}
template <typename T, typename ...Ts> void read(T& v, Ts& ...ts) { v = read<T>(); read(ts...); }
template <typename T> void readv(i64 n, std::vector<T>& v) { for (i64 i = 0; i < n; i++) v.push_back(read<T>()); }
template <typename T> std::vector<T> readv(i64 n) { std::vector<T> v; readv(n, v); return v; }
#define PRINTERS(FNAME, OUTP) \
    void FNAME() {} \
    template <typename T> void FNAME(const T& t) { OUTP << t; } \
    template <typename T1, typename T2, typename ...Ts> \
    void FNAME(const T1& t1, const T2& t2, const Ts& ...ts) { OUTP << t1 << ' '; FNAME(t2, ts...); } \
    template <typename ...Ts> \
    void FNAME##ln(const Ts& ...ts) { FNAME(ts...); FNAME('\n'); } \
    template <typename T, typename F> void FNAME##v(const T& t, F f) { for (i64 i = 0; i < isize(t); i++) if (i == isize(t) - 1) FNAME(f(t[i])); else FNAME(f(t[i]), ""); FNAME##ln(); } \
    template <typename T> void FNAME##v(const T& t) { FNAME##v(t, fun::identity<typename T::value_type>); }
PRINTERS(print, std::cout)
PRINTERS(lprint, std::cerr)
#ifdef DEBUG_PRINTS
    PRINTERS(dprint, std::cerr)
#else
# define dprint(...)
# define dprintv(...)
# define dprintln(...)
#endif
// }}}
template <typename T> bool vector_less(const std::vector<T>& v1, const std::vector<T>& v2) {
    massert(v1.size() == v2.size(), "wrong value len");
    for (size_t i = 0; i < v1.size(); i++) if (v1[i] != v2[i]) return v1[i] < v2[i];
    return false;
}


bool has_dups;

bool is_different_by_1(const string& s0, const string& s2) {
    i64 diffs = 0;
    for (i64 i = 0; i < isize(s0); i++) {
        diffs += (s0[i] != s2[i]);
    }
    if (has_dups)
        return diffs <= 2;
    else
        return diffs == 2;
}
bool are_different_by_1(const string& s0, const vector<string>& v) {
    for (auto s2 : v)
        if (!is_different_by_1(s0, s2))
            return false;
    return true;
}

vector<i64> get_diff_indices(const string& s1, const string& s2) {
    vector<i64> diffs;
    for (i64 i = 0; i < isize(s1); i++) {
        if (s1[i] != s2[i])
            diffs.push_back(i);
    }
    return diffs;
}
bool the_same_characters(string s1, string s2) {
    sort(s1.begin(), s1.end());
    sort(s2.begin(), s2.end());
    return s1 == s2;
}
bool has_duplicated_characters(string s) {
    sort(s.begin(), s.end());
    for (i64 i = 0; i + 1 < isize(s); i++)
        if (s[i] == s[i + 1])
            return true;
    return false;
}

string res(vector<string> v) {
    const string s0 = v.front();
    has_dups = has_duplicated_characters(s0);
    v.erase(v.begin());
    if (v.empty()) {
        auto s00 = s0;
        swap(s00[0], s00[1]);
        return s00;
    }
    for (auto s : v)
        if (!the_same_characters(s0, s))
            return "";
    vector<i64> ids = get_diff_indices(s0, v[0]);
    if (isize(ids) > 4)
        return "";
    for (auto i1 : ids)
        for (auto i2 : ids)
            if (i1 != i2) {
                string s00 = s0;
                swap(s00[i1], s00[i2]);
                if (are_different_by_1(s00, v))
                    return s00;
            }
    return "";
}

void go() {
    i64 n, l;
    read(n, l);
    auto v = readv<string>(n);
    auto r = res(v);
    println(r.empty() ? "-1" : r);
}

int main () { // {{{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    go();
} //
