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 Task{
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.flush();out.close();
    }
        static class TaskE {
        int n,k;
        char c[][];
        char cx[][];
        boolean rep=false;
        int ar[]={-1,-1,2,3,2};
        int p[];

        ArrayList<Integer> not(int id1,int id2){
        	ArrayList<Integer> r=new ArrayList<>();
        	for(int i=0;i<k;i++){
        		if(c[id1][i]!=c[id2][i])r.add(i);
        	}
        	boolean is=true;
        	if(r.size()==4){
        		is=false;
        		int p[]=new int[4];
        		for(int i=0;i<4;i++)p[i]=r.get(i);
        		int ar[][]={{p[2],p[3]},{p[1],p[3]},{p[1],p[2]}};
        		for(int i=1;i<=3;i++){
        			if(c[id1][p[0]]==c[id2][p[i]]&&c[id2][p[0]]==c[id1][p[i]]
        				&&c[id1][ar[i-1][0]]==c[id2][ar[i-1][1]]&&c[id2][ar[i-1][0]]==c[id1][ar[i-1][1]]){
        				r.clear();
        				r.add(p[0]);r.add(p[i]);r.add(ar[i-1][0]);r.add(ar[i-1][1]);
        				is=true;break;
        			}
        		}
        	}if(!is)r.add(-1);
        	return r;
        }
        
        boolean verify(int id1,int id2){
        	int cnt=0;int x[]=new int[2];
        	for(int i=0;i<k;i++){
        		if(cx[id1][i]!=c[id2][i]){
        			++cnt;
        			if(cnt==3)break;
        			x[cnt-1]=i;
        		}
        	}
        	if((cnt==2&&cx[id1][x[0]]==c[id2][x[1]]&&cx[id1][x[1]]==c[id2][x[0]])||(cnt==0&&rep))return true;
        	return false;
        }

        void swap(int id,int p0,int p1){
        	// p0=p[p0];p1=p[p1];
        	char t=cx[id][p0];
 			cx[id][p0]=cx[id][p1];
 			cx[id][p1]=t;
        }

	 	  public void solve(int testNumber, InputReader in, PrintWriter out) {
 			n=in.nextInt();k=in.nextInt();
 			c=new char[n][];
 			int f[]=new int[26];
 			for(int i=0;i<n;i++){
 				c[i]=in.next().trim().toCharArray();
 			}
 			for(int i=0;i<k;i++){
 				if(++f[c[0][i]-'a']==2)rep=true;
 			}

 			int isd=-1;boolean r=true;
 			int x=-1;ArrayList<Integer> al=new ArrayList<>();
 			for(int i=1;i<n;i++){
 				al=not(0,i);
 				x=al.size();
 				if(x!=0){
 					if(x==1||x>4){
 						r=false;
 					}else{
 						isd=i;
 					}
 					break;
 				}
 			}

 			if(!r){
 				out.print("-1");return;
 			}

 			if(isd==-1){
 				char t=c[0][0];
 				c[0][0]=c[0][1];
 				c[0][1]=t;
 				for(int i=0;i<k;i++)out.print(c[0][i]);
 				return;
 			}

 			p=new int[x];
 			for(int i=0;i<x;i++)p[i]=al.get(i);
 			
            if(x==2)ar[x]=f[c[0][p[0]]-'a']+f[c[0][p[1]]-'a']+1;
 			cx=new char[ar[x]][k];
 			for(int i=0;i<ar[x];i++){
 				for(int j=0;j<k;j++)cx[i][j]=c[0][j];
 			}
 			
 			// System.out.println(x);

 			if(x==2){
                int px=0;
                for(int it=0;it<2;it++){
                    for(int i=0;i<k;i++){
                        if(c[0][i]==c[0][p[1-it]]){
                            // System.out.println(px+" "+p[it]+" "+i);
                            swap(++px,p[it],i);
                        }
                    }
                }
 			}else if(x==3){
 				swap(0,p[0],p[1]);
 				swap(1,p[1],p[2]);
 				swap(2,p[0],p[2]);
 			}else{
 				swap(0,p[0],p[1]);
 				swap(1,p[2],p[3]);
 			}

 			for(int i=0;i<ar[x];i++){
 				boolean r1=true;
 				for(int j=0;j<n;j++){
 					if(!verify(i,j)){
 						r1=false;break;
 					}
 				}
 				if(r1){
 					for(int j=0;j<k;j++)out.print(cx[i][j]);
 					return;
 				}
 			}out.print("-1");
          }
//         pair ja[][];long w[];int from[],to[],c[];
//             void make(int n,int m,InputReader in){
//              ja=new pair[n+1][];w=new long[m];from=new int[m];to=new int[m];c=new int[n+1];
//              for(int i=0;i<m;i++){
//               int u=in.nextInt(),v=in.nextInt();long wt=in.nextLong();
//               c[u]++;c[v]++;from[i]=u;to[i]=v;w[i]=wt;
//              }
//              for(int i=1;i<=n;i++){
//               ja[i]=new pair[c[i]];c[i]=0;
//              }
//              for(int i=0;i<m;i++){
//               ja[from[i]][c[from[i]]++]=new pair(to[i],w[i]);
//               ja[to[i]][c[to[i]]++]=new pair(from[i],w[i]);
//              }
//             }
//        int[] radixSort(int[] f){ return radixSort(f, f.length); }
//	int[] radixSort(int[] f, int n)
//	{
//		int[] to = new int[n];
//		{
//			int[] b = new int[65537];
//			for(int i = 0;i < n;i++)b[1+(f[i]&0xffff)]++;
//			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
//			for(int i = 0;i < n;i++)to[b[f[i]&0xffff]++] = f[i];
//			int[] d = f; f = to;to = d;
//		}
//		{
//			int[] b = new int[65537];
//			for(int i = 0;i < n;i++)b[1+(f[i]>>>16)]++;
//			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
//			for(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];
//			int[] d = f; f = to;to = d;
//		}
//		return f;
//	}
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}