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.*;
import java.util.*;

public class Main {
    public Main() throws IOException {
    }

    static boolean isDistincString(String s) {
        Set<Character> set = new HashSet<>();
        int n = s.length();
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            if (set.contains(c)) return false;
            set.add(c);
        }
        return true;
    }

    static String swapString(String s, int i , int j) {
        StringBuilder res = new StringBuilder(s);
        res.setCharAt(i, s.charAt(j));
        res.setCharAt(j, s.charAt(i));
        return res.toString();
    }

    static boolean beSwapped(String s, String t) {
        int n = s.length();
        if (!isDistincString(s) && s.equals(t)) return true;
        ArrayList<Integer> unmatched = new ArrayList<>();
        for (int j = 0; j < n; j++) {
            if (s.charAt(j) != t.charAt(j)) unmatched.add(j);
        }
        if (unmatched.size() == 2) {
            int a = unmatched.get(0), b = unmatched.get(1);
            return t.equals(swapString(s, a, b));
        }
        return false;
    }

    static void solve() throws IOException {
        rl(); int k = ni2(), n = ni2();
        String s[] = new String[k];
        for (int i = 0; i < k; i++) s[i] = input.readLine();
        if (k == 1) {
            ans.append(swapString(s[0], 0, 1));
        } else {
            int i = 1;
            while (i < k) {
                if (s[i].equals(s[0])) i++;
                else break;
            }
            if (i == k) {
                ans.append(swapString(s[0], 0, 1));
            } else {
                ArrayList<Integer> unmatched = new ArrayList<>();
                for (int j = 0; j < n; j++) {
                    if (s[0].charAt(j) != s[i].charAt(j)) unmatched.add(j);
                }
                int unmatchedSize = unmatched.size();
                ArrayList<String> target = new ArrayList<>();
                int a, b, c, d;
                switch (unmatchedSize) {
                    case 1:
                        ans.append("-1"); break;
                    case 2:
                        if (isDistincString(s[0]) && isDistincString(s[i])) ans.append("-1");
                        else {
                            a = unmatched.get(0); b = unmatched.get(1);
                            if (s[0].charAt(a) == s[i].charAt(b) && s[0].charAt(b) == s[i].charAt(a)) {
                                target.add(s[0]);
                                for (int j = 0; j < n; j++) {
                                    if (s[0].charAt(j) == s[0].charAt(b)) target.add(swapString(s[0], a, j));
                                    if (s[0].charAt(j) == s[0].charAt(a)) target.add(swapString(s[0], b, j));
                                }
                            } else ans.append("-1");
                        }
                        break;
                    case 3:
                        a = unmatched.get(0); b = unmatched.get(1); c = unmatched.get(2);
                        char sa = s[0].charAt(a), sb = s[0].charAt(b), sc = s[0].charAt(c);
                        char ta = s[i].charAt(a), tb = s[i].charAt(b), tc = s[i].charAt(c);
                        if ((sa == tb && sb == tc && sc == ta) || (sa == tc && sb == ta && sc == tb)) {
                            target.add(swapString(s[0], a, b));
                            target.add(swapString(s[0], b, c));
                            target.add(swapString(s[0], c, a));
                        } else {
                            ans.append("-1");
                        }
                        break;
                    case 4:
                        a = unmatched.get(0); b = unmatched.get(1); c = unmatched.get(2); d = unmatched.get(3);
                        if (s[0].charAt(a) == s[i].charAt(b) && s[0].charAt(b) == s[i].charAt(a) &&
                                s[0].charAt(c) == s[i].charAt(d) && s[0].charAt(d) == s[i].charAt(c)) {
                            target.add(swapString(s[0], a, b));
                            target.add(swapString(s[0], c, d));
                        } else if (s[0].charAt(a) == s[i].charAt(c) && s[0].charAt(c) == s[i].charAt(a) &&
                                s[0].charAt(b) == s[i].charAt(d) && s[0].charAt(d) == s[i].charAt(b)) {
                            target.add(swapString(s[0], a, c));
                            target.add(swapString(s[0], b, d));
                        } else if (s[0].charAt(a) == s[i].charAt(d) && s[0].charAt(d) == s[i].charAt(a) &&
                                s[0].charAt(b) == s[i].charAt(c) && s[0].charAt(c) == s[i].charAt(b)) {
                            target.add(swapString(s[0], a, d));
                            target.add(swapString(s[0], b, c));
                        } else {
                            ans.append("-1");
                        }
                        break;

                        default: ans.append("-1");
                }

                if (ans.length() == 0) {
                    boolean possible = true;
//                    System.out.println(target);
                    for (String t : target) {
                        possible = true;
                        for (int j = i; j < k; j++) {
                            if (!beSwapped(t, s[j])) {
                                possible = false;
                                break;
                            }
                        }
                        if (possible) {
                            ans.append(t);
                            break;
                        }
                    }
                    if (!possible) ans.append("-1");
                }
            }
        }

        output.write(ans.toString());
        output.flush();
        output.close();
    }

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


    static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
    static StringBuilder ans = new StringBuilder();
    static StringTokenizer stringTokenizer;

    static int ni1() throws IOException {
        return Integer.parseInt(input.readLine());
    }

    static int ni2() throws IOException {
        return Integer.parseInt(stringTokenizer.nextToken());
    }

    static long nl1() throws IOException {
        return Long.parseLong(input.readLine());
    }

    static long nl2() {
        return Long.parseLong(stringTokenizer.nextToken());
    }

    static void rl() throws IOException {
        stringTokenizer = new StringTokenizer(input.readLine());
    }
}