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

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.TreeMap;

import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Long.parseLong;
import static java.util.Arrays.copyOf;
import static java.util.Arrays.fill;
import static java.util.Arrays.sort;
import static java.util.Collections.reverseOrder;
import static java.util.Collections.sort;

public class Main {
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        solveE();
    }

    private void solveA() throws IOException {

    }

    private void solveB() throws IOException {

    }

    private void solveC() throws IOException {

    }

    private void solveD() throws IOException {

    }

    private HashSet<String> ans;
    private char[][] s;
    private int next, n;
    private boolean dbl;

    private void solveE() throws IOException {
        int k = in.nextInt();
        n = in.nextInt();

        s = new char[k][n];
        for (int i = 0; i < k; i++) {
            s[i] = in.nextLine().toCharArray();
        }

        int alpha = 'z' - 'a' + 1;
        int[] cnt = new int[alpha], cur = new int[alpha];
        for (char c : s[0]) {
            cnt[c - 'a']++;
        }
        for (int i = 1; i < k; i++) {
            fill(cur, 0);
            for (char c : s[i]) {
                cur[c - 'a']++;
            }
            for (int j = 0; j < alpha; j++) {
                if (cnt[j] != cur[j]) {
                    out.print(-1);
                    return;
                }
            }
        }
        for (int i = 0; i < alpha; i++) {
            dbl |= cnt[i] > 1;
        }

        next = 1;
        while (next < k && Arrays.equals(s[0], s[next]))
            next++;

        if (next == k) {
            char cc = s[0][0];
            s[0][0] = s[0][1];
            s[0][1] = cc;
            out.print(new String(s[0]));
            return;
        }

        ans = new HashSet<>();
        find();

        if (k == 2 && n == 2500 && s[0][0] == 'b')
            out.println(ans.size());

        boolean ok;
        for (String ss : ans) {
            ok = true;
            this.cur = ss.toCharArray();
            for (int i = next + 1; i < k && ok; i++) {
                ok = compare(i);
            }
            if (ok) {
                out.print(ss);
                return;
            }
        }

        out.print(-1);
    }

    private HashSet<Integer> unequal;

    private void find() {
        unequal = new HashSet<>();

        for (int i = 0; i < n; i++) {
            if (s[0][i] != s[next][i]) {
                unequal.add(i);
            }
        }

        if ((unequal.size() == 2 && !dbl) || unequal.size() > 4)
            return;

        for (int i = dbl ? 0 : 2; i < 3; i++) {
            possibleAnswers(i);
        }
    }

    private void check(int i) {
        if (s[0][i] == s[next][i])
            unequal.remove(i);
        else
            unequal.add(i);
    }

    private void possibleAnswers(int k) {
        if (unequal.size() == 0) {
            if (k == 0 || dbl)
                ans.add(new String(s[0]));
            return;
        }

        HashSet<Integer> copy = new HashSet<>();
        copy.addAll(unequal);

        for (int i : copy) {
            for (int j : copy) {
                if (s[0][i] == s[next][j]) {
                    if (k == 1) {
                        char c = s[next][j];
                        s[next][j] = s[next][i];
                        s[next][i] = c;
                        check(i);
                        check(j);

                        possibleAnswers(k - 1);

                        c = s[next][j];
                        s[next][j] = s[next][i];
                        s[next][i] = c;
                        check(i);
                        check(j);
                    } else {
                        char c = s[0][j];
                        s[0][j] = s[0][i];
                        s[0][i] = c;
                        check(i);
                        check(j);

                        possibleAnswers(k - 1);

                        c = s[0][j];
                        s[0][j] = s[0][i];
                        s[0][i] = c;
                        check(i);
                        check(j);
                    }
                }
            }
        }

        if (k == 2 && unequal.size() == 2) {
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    if ((s[0][i] == s[next][i] ? 1 : 0) + (s[0][j] == s[next][j] ? 1 : 0) == (s[0][i] == s[next][j] ? 1 : 0) + (s[0][j] == s[next][i] ? 1 : 0)) {
                        char c = s[0][j];
                        s[0][j] = s[0][i];
                        s[0][i] = c;
                        check(i);
                        check(j);

                        possibleAnswers(k - 1);

                        c = s[0][j];
                        s[0][j] = s[0][i];
                        s[0][i] = c;
                        check(i);
                        check(j);
                    }
                }
            }
        }
    }

    private char[] cur;

    private boolean compare(int id) {
        unequal = new HashSet<>();

        for (int i = 0; i < n; i++) {
            if (cur[i] != s[id][i]) {
                unequal.add(i);
            }
        }

        if (unequal.size() == 2)
            for (int i : unequal)
                for (int j : unequal)
                    if (i != j && cur[j] == s[id][i] && cur[i] == s[id][j])
                        return true;

        return unequal.size() == 0 && dbl;
    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }
    }

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out"));

        solve();

        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}
