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

/*
 * start with k identical string, swap exactly 2 char in each string, s1...sk
 * find a string that can be transformed to s1 to sk per rule above
 * string len=n. 1 ≤ k ≤ 2500, 2 ≤ n ≤ 5000, k · n ≤ 5000
 */


import static java.lang.System.out;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class SwappingChar {
    
    TreeSet<String> unique=new TreeSet<>();
    SwappingChar(List<String> ss )
    {
        for(String s:ss)
            unique.add(s);
    }
    private String swap(String s, int pos1, int pos2)
    {        
        StringBuilder sb=new StringBuilder();
        sb.append(s);
        sb.setCharAt(pos1, s.charAt(pos2));
        sb.setCharAt(pos2, s.charAt(pos1));
        return sb.toString();
    }
    String solve()
    {
        if (unique.size()==1) {
            String ans = unique.first();  // swap last 2 char
            return ans.substring(0, ans.length()-2)+ans.charAt(ans.length()-1)+ans.charAt(ans.length()-2);
        }
        // compare 1st string to rest, validate same length, diff position is <=4, chars are same
        String[] u= unique.toArray(new String[unique.size()]);
        for (int i=1; i<u.length; i++) {
            if (u[0].length()!=u[i].length())  // string must be of same length
                return "-1";
            ArrayList<Character> diff1=new ArrayList<>();
            ArrayList<Character> diff2=new ArrayList<>();
            int count=0;
            for (int j=0; j<u[0].length(); j++) {
                if (u[0].charAt(j) !=u[i].charAt(j)) {
                    diff1.add(u[0].charAt(j));
                    diff2.add(u[i].charAt(j));
                    if (++count>4)  // difference char position should exceed 4
                        return "-1";
                }
            }
            Collections.sort(diff1);  // char that diffs between 2 string must be same
            Collections.sort(diff2);
            for (int k=0; k<diff1.size(); k++) {
                if (diff1.get(k)!=diff2.get(k))
                    return "-1";
            }
        }
        // find position of diff char of first 2 string
        ArrayList<Integer> diff1=new ArrayList<>();
        for (int j=0; j<u[0].length(); j++) {
            if (u[0].charAt(j) !=u[1].charAt(j))
                diff1.add(j);
        }
        TreeSet<String> candidates=new TreeSet<>();
        for (int k=0; k<diff1.size(); k++) {
            for (int j=0; j<u[0].length(); j++) {  // swap diff with any char in string
                candidates.add(swap(u[0], j, diff1.get(k)));
                //candidates.add(swap(u[1], j, diff1.get(k)));
            }
        }
        //out.println(Arrays.toString(u));
        //out.println(diff1);
        //out.println(candidates);
        boolean dup=u[0].length()>26; // string has some duplicate letter of same value
        if (dup) {
            Set<Character> letters=new HashSet<>();
            for (int i=0; i< u[0].length(); i++)
                letters.add(u[0].charAt(i));
            dup=u[0].length()>letters.size();
        }
        for (String s: candidates) {
            int i=1;
            for (; i<u.length; i++) {
                int count=0;
                for (int j=0; j<s.length(); j++) {
                    if (s.charAt(j) !=u[i].charAt(j))
                        count++;  
                }
                if (count !=0 && count !=2)
                    break;           
            }
            if (i==u.length)
                return s;
        }
        return "-1";
    }
    static void test()
    {
        ArrayList<String> in=new ArrayList<>();
        in.add("te");
        out.println(new SwappingChar(in).solve());
        in.add("ab");
        out.println(new SwappingChar(in).solve());
        in.set(1, "tetete");
        out.println(new SwappingChar(in).solve());
        in.set(0, "etetet");
        out.println(new SwappingChar(in).solve());
        in.set(0, "abac");
        in.set(1, "caab");
        in.add("acba");
        out.println(new SwappingChar(in).solve());
        in.set(0, "kbbu");
        in.set(1, "kbub");
        in.set(2,"ubkb");
        out.println(new SwappingChar(in).solve());
        in.set(0, "clo");
        in.set(1, "col");
        in.set(2, "lco");
        out.println(new SwappingChar(in).solve());
    }
    public static void main(String[] args)
    {      
        judge();
    }
    static void judge()
    {        
        int k=IOR.ni();  // 1 to2500 
        int n=IOR.ni(); // 2 to 5000
        ArrayList<String> s=new ArrayList<>(k);
        for (int i=0; i<k; i++) {
            s.add(IOR.ns());
        }
        out.println(new SwappingChar(s).solve());
    }
}
class IOR {
    
    private static Scanner sc = new Scanner(System.in);    
        
    public static int ni()
    {
        return sc.nextInt();
    }
    public static long nl()
    {
        return sc.nextLong();
    }
    public static String ns()
    {
        return sc.next();
    }
    
    public static List<Integer> riL(int N) { // read int array list
        List<Integer> L=new ArrayList<>();
        for (int i=0; i<N; i++)
            L.add(sc.nextInt());
        return L;
    }
    
    public static int[] ria(int N) { // read int array
        int L[]=new int[N];
        for (int i=0; i<N; i++)
            L[i]=sc.nextInt();
        return L;
    }
    
    public static int[] ria1(int N) { // read int array, from 1
        int L[]=new int[N];
        for (int i=1; i<N; i++)
            L[i]=sc.nextInt();
        return L;
    }
    
    public static int[][] fillMatrix(int n, int m)
    {
        int a[][]=new int[n][m];
        for (int i=0; i<a.length; i++)
            for (int j=0; j<a[i].length; j++) {
                a[i][j]=sc.nextInt();
            }
        return a;
    }

    public static void fileScanner(Scanner s)
    {
        sc = s;
    }
}