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.util.*;
import java.lang.*;
import java.io.*;
public class E903
{
	static int n,len;
	static int compare(String s1,String s2)
	{
		int sum=0;
		char[] temparr=new char[len];
		char[] temparr2=new char[len];
		temparr=s1.toCharArray();
		temparr2=s2.toCharArray();
		for(int i3=0;i3<len;i3++)
		{
			if (temparr[i3]!=temparr2[i3])
				sum++;
		}
		return sum;
	}
	/*static String returnn(char[] temparr,char[] temparr2,Vector<Integer> v)
	{
		//System.out.println("temparr is "+temparr[2]);
		char[] vtemp1=new char[len];
		char[] vtemp2=new char[len];
		char[] vtemp3=new char[len];
		String tparent;
		//char[] vtemp4=new char[len];
		//char[] vtemp5=new char[len];
		//char[] vtemp6=new char[len];
		char ch;
		int sum=0;
		for(int i=0;i<len;i++)
		{
			vtemp1[i]=temparr[i];
			vtemp2[i]=temparr[i];
			vtemp3[i]=temparr[i];
		}
		
		//System.out.println("temparr is "+String.valueOf(temparr));
		//System.out.println("temparr2 is "+String.valueOf(temparr2));
		ch=vtemp1[v.get(0)];
		System.out.println("ch is "+ch);
		vtemp1[v.get(0)]=vtemp1[v.get(1)];
		vtemp1[v.get(1)]=ch;
		System.out.println("vtem1 is "+String.valueOf(vtemp1));



		
		ch=vtemp2[v.get(1)];
		vtemp2[v.get(1)]=vtemp2[v.get(2)];
		vtemp2[v.get(2)]=ch;
		System.out.println("vtem2 is "+String.valueOf(vtemp2));

		
		ch=vtemp3[v.get(2)];
		vtemp3[v.get(2)]=vtemp3[v.get(0)];
		vtemp3[v.get(0)]=ch;	
		System.out.println("vtem3 is "+String.valueOf(vtemp3));

		for(int i=0;i<3;i++)
		{
			if(vtemp1[v.get(i)]!=temparr2[v.get(i)])
				sum++;
		}
		if(sum==2)
		{
			System.out.println("22322");
			System.out.println("vtem1 is "+String.valueOf(vtemp1));
			return String.valueOf(vtemp1);
		}
		else 
			sum=0;

		
		for(int i=0;i<len;i++)
		{
			if(vtemp2[i]!=temparr2[i])
				sum++;
		}
		if(sum==2)
		{
			System.out.println("3333");

			return String.valueOf(vtemp2);
		}
		else
			sum=0;
		for(int i=0;i<len;i++)
		{
			if(vtemp3[i]!=temparr2[i])
				sum++;
		}
		if(sum==2)
		{
			System.out.println("4444");

			return String.valueOf(vtemp3);
		}
		else
			sum=0;
		return ("error 5");



	}*/
	public static void main(String[] args) 
	{
		int not=0,f1,f2,f3,f4;
		Scanner s= new Scanner(System.in);
		n=s.nextInt();
		len=s.nextInt();
		char ch;
		String parent1="c1",parent2="c2",parent3="c3",tparent="cc";
		char[] temparr=new char[len];
		char[] temparr2=new char[len];
		char[] temparr3=new char[len];
		Vector<Integer> v=new Vector<Integer>();
		Vector<String> v2=new Vector<String>();
		String[] arr=new String[n];
	
		arr[0]=s.next();
		temparr=arr[0].toCharArray();
		int initialsum=1,sum=1;
		for(int j=0;j<len;j++)
		{
			initialsum=(initialsum*((int)temparr[j]))%20000;
		}

		for(int i=1;i<n;i++)
		{
			arr[i]=s.next();
			temparr=arr[i].toCharArray();
			sum=1;
			for(int j=0;j<len;j++)
			{
				sum=(sum*((int)temparr[j]))%20000;

			}
			if(sum!=initialsum)
			{

					//System.out.println("here5");
				System.out.println("-1");
				System.exit(0);
			}
		}
		v2.add(arr[0]);
		for(int i=1;i<n;i++)
		{
			if(v2.contains(arr[i]))
			{

			}
			else
			{
				v2.add(arr[i]);
			}
		}
		n=v2.size();
		arr=new String[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=v2.get(i);
		}
		temparr=arr[0].toCharArray();

		if(n==1)
		{
			//System.out.println("yesy");
			ch=temparr[0];
			temparr[0]=temparr[1];
			temparr[1]=ch;
			tparent=String.valueOf(temparr);
			System.out.println(tparent);
			System.exit(0);
		}
		temparr2=arr[1].toCharArray();
		for(int i=0;i<len;i++)
		{
			if(temparr[i]!=temparr2[i])
				v.add(i);
		}
		if(n==2&&v.size()==0)
		{
				ch=temparr[0];
			temparr[0]=temparr[1];
			temparr[1]=ch;
			tparent=String.valueOf(temparr);
			System.out.println(tparent);
			System.exit(0);
		}

		if(len==2)
		{
			if(arr[0].equals(arr[1]))
			{
				//System.out.println("yes");
				ch=temparr[0];
				temparr[0]=temparr[1];
				temparr[1]=ch;
				tparent=String.valueOf(temparr);
				not=0;
				for(int i2=2;i2<n;i2++)
				{  
				//	System.out.println(compare(arr[2],tparent)+"tparent is "+tparent);
					if(compare(arr[i2],tparent)==2||compare(arr[i2],tparent)==0)//||compare(arr[i2],tparent)==2)
					{
						//not=1;
					}
					else
					{
						not=1;
						break;
					}
				}
				//System.out.println("not is "+not);
				if(not==0)
				{
					System.out.println(tparent);
					System.exit(0);
				}
					
				else
				{

				//	System.out.println("here4");
					System.out.println("-1");
					System.exit(0);
				}
			}
			else
			{

				//	System.out.println("here3");
				System.out.println("-1");
				System.exit(0);
			}


		}
		//System.out.println(v);
		if(v.size()>=5)
			System.out.println("-1");
		if(v.size()==4)
		{
			//System.out.println("yes");
			int t=v.get(0);
			if(temparr[v.get(0)]==temparr2[v.get(1)])
			{
				f1=0;
				f2=1;
				f3=2;
				f4=3;
			}
			else if (temparr[v.get(0)]==temparr2[v.get(2)]) 
			{
				f1=0;
				f2=2;
				f3=3;
				f4=1;
			}
			else//if(temparr[v.get(0)]==temparr2[v.get(3)])
			{
				f1=0;
				f2=3;
				f3=1;
				f4=2;
			}
			/*else
			{
				System.out.println("big screwup");
			}*/
			//if(temparr[v.get(0)]==temparr2[v.get(1)])
			//{
			
			for(int ij=0;ij<len;ij++)
			{
				temparr3[ij]=temparr[ij];
			}
			ch=temparr3[v.get(f1)];
			temparr3[v.get(f1)]=temparr3[v.get(f2)];
			temparr3[v.get(f2)]=ch;
			parent1=String.valueOf(temparr3);
			for(int ij=0;ij<len;ij++)
			{
				temparr3[ij]=temparr[ij];
			}
			//temparr3=temparr;
			ch=temparr3[v.get(f3)];
			temparr3[v.get(f3)]=temparr3[v.get(f4)];
			temparr3[v.get(f4)]=ch;
			parent2=String.valueOf(temparr3);
			//}
			tparent=parent1;
			for(int i2=2;i2<n;i2++)
			{
				if(compare(arr[i2],parent1)==0||compare(arr[i2],parent1)==2)
				{
					//not=1;
				}
				else
				{
					not=1;
					break;
				}
			}
			if(not==1)
			{
				not=0;
				for(int i2=2;i2<n;i2++)
				{  
					if(compare(arr[i2],parent2)==0||compare(arr[i2],parent2)==2)
					{
						//not=1;
					}
					else
					{
						not=1;
						break;
					}
				}
				if(not==0)
					tparent=parent2;
				else
				{

					//System.out.println("here2");
					System.out.println("-1");
					System.exit(0);
				}
				
			}
		}
		else if(v.size()==2)
		{
			parent1=String.valueOf(temparr);
			parent2=String.valueOf(temparr2);
			tparent=parent1;
			for(int i2=2;i2<n;i2++)
			{
				if(compare(arr[i2],parent1)==0||compare(arr[i2],parent1)==2)
				{
					//not=1;
				}
				else
				{
					not=1;
					break;
				}
			}
			//System.out.println("not is "+not);
			if(not==1)
			{
				not=0;
				for(int i2=2;i2<n;i2++)
				{  
					if(compare(arr[i2],parent2)==0||compare(arr[i2],parent2)==2)
					{
						//not=1;
					}
					else
					{
						not=1;
						break;
					}
				}
				if(not==0)
					tparent=parent2;
				else
				{
					//System.out.println("here1");
					System.out.println("-1");
					System.exit(0);
				}				
			}
		}
		else if(v.size()==3)
		{
			/*char[] vtemp=new char[len];
			vtemp=temparr2;
			ch=vtemp[v.get(0)]
			vtemp[v.get(0)]=vtemp[v.get(1)];
			vtemp[v.get(1)]=ch;
			parent1=String.valueOf(vtemp);*/




			char[] vtemp1=new char[len];
		char[] vtemp2=new char[len];
		char[] vtemp3=new char[len];
		//String tparent;
		//char[] vtemp4=new char[len];
		//char[] vtemp5=new char[len];
		//char[] vtemp6=new char[len];
		
		int sum2=0;
		for(int i=0;i<len;i++)
		{
			vtemp1[i]=temparr[i];
			vtemp2[i]=temparr[i];
			vtemp3[i]=temparr[i];
		}
		
		//System.out.println("temparr is "+String.valueOf(temparr));
		//System.out.println("temparr2 is "+String.valueOf(temparr2));
		ch=vtemp1[v.get(0)];
		//System.out.println("ch is "+ch);
		vtemp1[v.get(0)]=vtemp1[v.get(1)];
		vtemp1[v.get(1)]=ch;
		//System.out.println("vtem1 is "+String.valueOf(vtemp1));



		
		ch=vtemp2[v.get(1)];
		vtemp2[v.get(1)]=vtemp2[v.get(2)];
		vtemp2[v.get(2)]=ch;
	    //System.out.println("vtem2 is "+String.valueOf(vtemp2));

		
		ch=vtemp3[v.get(2)];
		vtemp3[v.get(2)]=vtemp3[v.get(0)];
		vtemp3[v.get(0)]=ch;	
		//System.out.println("vtem3 is "+String.valueOf(vtemp3));

		for(int i=0;i<3;i++)
		{
			if(vtemp1[v.get(i)]!=temparr2[v.get(i)])
				sum2++;
		}
		if(sum2==2)
		{
			//System.out.println("22322");
			//System.out.println("vtem1 is "+String.valueOf(vtemp1));
			parent1= String.valueOf(vtemp1);
		}
		//else 
		sum2=0;

		
		for(int i=0;i<len;i++)
		{
			if(vtemp2[i]!=temparr2[i])
				sum2++;
		}
		if(sum2==2)
		{
		//	System.out.println("3333");

			parent2=String.valueOf(vtemp2);
		}
		//else
		sum2=0;
		for(int i=0;i<len;i++)
		{
			if(vtemp3[i]!=temparr2[i])
				sum2++;
		}
		if(sum2==2)
		{
			//System.out.println("4444");

			parent3=String.valueOf(vtemp3);
		}



			//tparent=returnn(temparr,temparr2,v);
			//System.out.println("tparent is "+tparent);
		tparent=parent1;
			for(int i2=2;i2<n;i2++)
			{  
				if(compare(arr[i2],parent1)==0||compare(arr[i2],parent1)==2)
				{
						//not=1;
				}
				else
				{
					not=1;
					break;
					//System.out.println("-1");
					//System.exit(0);
				}
			}
			if(not==1)
			{
				not=0;
				tparent=parent2;
				for(int i2=2;i2<n;i2++)
				{  
					if(compare(arr[i2],parent2)==0||compare(arr[i2],parent2)==2)
					{
						//not=1;
					}
					else
					{
						not=1;
						break;
					//System.out.println("-1");
					//System.exit(0);
					}
				}
			}
			if(not==1)
			{
				not=0;
				tparent=parent3;
				for(int i2=2;i2<n;i2++)
				{  
					if(compare(arr[i2],parent3)==0||compare(arr[i2],parent3)==2)
					{
						//not=1;
					}
					else
					{
						//not=1;
						//break;

				//	System.out.println("here6");
					System.out.println("-1");
					System.exit(0);
					}
				}
			}
			

		}
		System.out.println(tparent);

	}
}