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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author darkhan imangaliyev
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyReader in = new MyReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        @SuppressWarnings("unchecked")
        public void solve(int testNumber, MyReader in, PrintWriter out) {
            int k = in.nextInt(), n = in.nextInt();
            int[] f = new int[26];
            char[][] s = new char[k][n];
            boolean hasDuplicate = false;
            for (int i = 0; i < k; ++i) {
                s[i] = in.next().toCharArray();
                int[] c = new int[26];
                for (int j = 0; j < n; ++j) {
                    ++c[s[i][j] - 'a'];
                    if (c[s[i][j] - 'a'] > 1) {
                        hasDuplicate = true;
                    }
                }
                if (i == 0) {
                    f = c.clone();
                } else {
                    for (int j = 0; j < 26; ++j) {
                        if (f[j] != c[j]) {
                            out.println(-1);
                            return;
                        }
                    }
                }
            }
            boolean[][] pos = new boolean[k][n];
            int[] d = new int[k];
            for (int i = 1; i < k; ++i) {
                int diff = 0;
                for (int j = 0; j < n; ++j) {
                    if (s[0][j] != s[i][j]) {
                        ++diff;
                        pos[i][j] = true;
                    }
                }
                d[i] = diff;
            }
            for (int i = 0; i < n; ++i) {
                for (int j = i + 1; j < n; ++j) {
                    boolean ok = true;
                    for (int it = 1; it < k; ++it) {
                        int ham = update(pos[it], d[it], i, j, s[0], s[it]);
                        if (ham > 2) {
                            ok = false;
                            break;
                        } else if (ham == 0 && !hasDuplicate) {
                            ok = false;
                            break;
                        }
                    }
                    if (ok) {
                        char buff = s[0][i];
                        s[0][i] = s[0][j];
                        s[0][j] = buff;
                        out.println(new String(s[0]));
                        return;
                    }
                }
            }
            out.println(-1);
        }

        private int update(boolean[] pos, int oldHam, int pos1, int pos2, char[] s1, char[] s2) {
            if (pos[pos1] && pos[pos2]) {
                if (s1[pos1] == s2[pos2]) {
                    --oldHam;
                }
                if (s1[pos2] == s2[pos1]) {
                    --oldHam;
                }
            } else if (pos[pos1]) {
                if (s1[pos1] != s2[pos2]) {
                    ++oldHam;
                }
                if (s1[pos2] == s2[pos1]) {
                    --oldHam;
                }
            } else if (pos[pos2]) {
                if (s1[pos2] != s2[pos1]) {
                    ++oldHam;
                }
                if (s1[pos1] == s2[pos2]) {
                    --oldHam;
                }
            } else {
                if (s1[pos1] != s2[pos2]) {
                    ++oldHam;
                }
                if (s1[pos2] != s2[pos1]) {
                    ++oldHam;
                }
            }
            return oldHam;
        }

    }

    static class MyReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public MyReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}

