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 sun.security.util.Length;

import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;


public class E {

    public static void getPermutations(Integer[] ids, int id, boolean[] used, int[] current, ArrayList<int[]> result) {
        if (id == ids.length) {
            result.add(current.clone());
            return;
        }

        for (int i = 0; i < ids.length; ++i) {
            if (used[i])
                continue;
            used[i] = true;
            current[id] = ids[i];
            getPermutations(ids, id + 1, used, current, result);
            used[i] = false;
        }
    }

    public static List<int[]> getPermutations(Integer[] ids) {
        ArrayList<int[]> result = new ArrayList<>();
        getPermutations(ids, 0, new boolean[ids.length], new int[ids.length], result);

        return result;
    }

    public static boolean hasDouble(char[] str) {
        for (char c = 'a'; c <= 'z'; c++) {
            int cnt = 0;
            for (int i = 0; i < str.length; ++i) {
                if (str[i] == c)
                    cnt += 1;

                if (cnt >= 2)
                    return true;
            }
        }

        return false;
    }

    public static boolean test(char[] candidate, List<String> source) {
        boolean hasDouble = hasDouble(candidate);

        for (String str: source) {
            int id = -1;
            int notEqCnt = 0;

            for (int i = 0; i < candidate.length; ++i) {
                if (candidate[i] != str.charAt(i)) {
                    notEqCnt ++;
                    if (notEqCnt > 2)
                        return false;

                    if (notEqCnt == 1) {
                        id = i;
                        continue;
                    }

                    if (candidate[id] != str.charAt(i) || candidate[i] != str.charAt(id)) {
                        return false;
                    }
                }
            }
            if (notEqCnt == 1 || (notEqCnt == 0 && !hasDouble))
                return false;
        }

        return true;
    }


    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int n = scan.nextInt();

        scan.nextLine();
        String first = null;

        HashSet<Integer> diffIds = new HashSet<>(10);

        ArrayList<String> s = new ArrayList<>(k);

        for (int i = 0; i < k; ++i) {
            String str = scan.nextLine();
            s.add(str);
        }

        for (int i = 0; i < k; ++i) {
            String str = s.get(i);
            if (i == 0)
                first = str;

            for (int j = 0; j < n; ++j) {
                if (first.charAt(j) != str.charAt(j)) {
                    diffIds.add(j);
                }
            }

            if (diffIds.size() >= 6) {
                System.out.println(-1);
                return;
            }

            if (diffIds.size() >= 4){
                break;
            }
        }

        Integer[] ids = new Integer[diffIds.size()];
        diffIds.toArray(ids);

        List<int[]> perms = getPermutations(ids);
        char[] result = first.toCharArray().clone();

        for (int[] perm: perms) {
            for (int i = 0; i < ids.length; ++i) {
//                System.out.print(perm[i]);

                result[ids[i]] = first.charAt(perm[i]);
            }

//            System.out.println();
//            System.out.println(new String(result));

            if (test(result, s)) {
//                System.out.println("test success");
//                System.out.print(s.get(s.size() - 1));
                String toPrint = new String(result);
                System.out.println(toPrint);
                return;
            }
        }

        if (ids.length == 0) {
            result[0] = first.charAt(1);
            result[1] = first.charAt(0);
            System.out.println(new String(result));
            return;
        }

        System.out.println(-1);
    }
}


