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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.StringTokenizer;

public class e2 {

	public static void main(String args[]) throws IOException {
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// BEGIN HERE
		int n = in.nextInt();
		int m = in.nextInt();

		if (n == 1) {
			char c[] = in.next().toCharArray();
			char t = c[0];
			c[0] = c[1];
			c[1] = t;
			System.out.println(new String(c));
			return;
		}

		HashSet<String> pos = new HashSet<>();

		String prev = in.next();
		int freq[] = new int[300];
		for (char c : prev.toCharArray()) {
			freq[c]++;
		}
		boolean canBeSame = false;
		for (int i = 0; i < 300; i++) {
			if (freq[i] >= 2)
				canBeSame = true;
		}
		boolean first = true;
		boolean diff = false;
		for (int i = 0; i < n - 1; i++) {
			ArrayList<Integer> swaps = new ArrayList<>();
			String cur = in.next();
			for (int j = 0; j < cur.length(); j++) {
				if (cur.charAt(j) != prev.charAt(j)) {
					swaps.add(j);
				}
			}

			if (swaps.size() > 4 || swaps.size() == 1) {
				System.out.println(-1);
				return;
			}
			if (swaps.size() > 0) {
				diff = true;
			} else {
				continue;
			}
			HashSet<String> newPos1 = new HashSet<>();
			HashSet<String> newPos2 = new HashSet<>();
			char c1[] = cur.toCharArray();
			char c2[] = prev.toCharArray();

			for (int l = 0; l < swaps.size(); l++) {
				for (int j = l + 1; j < swaps.size(); j++) {
					char t = c1[swaps.get(l)];
					c1[swaps.get(l)] = c1[swaps.get(j)];
					c1[swaps.get(j)] = t;
					newPos1.add(new String(c1));
					c1[swaps.get(j)] = c1[swaps.get(l)];
					c1[swaps.get(l)] = t;

				}
				if (canBeSame)
					newPos1.add(cur);
			}

			for (int l = 0; l < swaps.size(); l++) {
				for (int j = l + 1; j < swaps.size(); j++) {
					char t = c2[swaps.get(l)];
					c2[swaps.get(l)] = c2[swaps.get(j)];
					c2[swaps.get(j)] = t;
					// System.out.println(swaps.get(l) + " " + swaps.get(j) + "
					// " + Arrays.toString(c2));
					newPos2.add(new String(c2));
					c2[swaps.get(j)] = c2[swaps.get(l)];
					c2[swaps.get(l)] = t;
				}
				if (canBeSame)
					newPos2.add(prev);
			}
			HashSet<String> intersect = new HashSet<>();
			for (String s : newPos1) {
				if (newPos2.contains(s))
					intersect.add(s);
			}
			HashSet<String> f = new HashSet<>();
			if (!first) {
				for (String s : pos) {
					if (intersect.contains(s))
						f.add(s);
				}
			} else {
				f = intersect;
				first = false;
			}
			prev = cur;
			pos = f;
			// System.out.println(swaps);
			// System.out.println(newPos1);
			// System.out.println(newPos2);
		}

		if (!diff) {
			char c[] = prev.toCharArray();
			char t = c[0];
			c[0] = c[1];
			c[1] = t;
			out.println(new String(c));
		} else if (pos.size() == 0) {
			out.println(-1);
		} else {
			for (String s : pos) {
				out.println(s);
				break;
			}
		}

		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream i) {
			br = new BufferedReader(new InputStreamReader(i));
			st = null;
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			if (st == null) {
				st = new StringTokenizer(br.readLine());
			}
			String line = st.nextToken("\n");
			st = null;
			return line;
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
	}

	public static class combinatorics {
		static long modInv(long a, long b) {
			return 1 < a ? b - modInv(b % a, a) * b / a : 1;
		}

		static long factorial[], mod;

		combinatorics(int n, long MOD) {
			mod = MOD;
			factorial = new long[n + 1];
			factorial[0] = 1;
			for (int i = 1; i <= n; i++) {
				factorial[i] = i * factorial[i - 1];
				factorial[i] %= mod;
			}
		}

		static long nCr(int n, int r) {
			if (r > n)
				return 0;
			return (factorial[n] * modInv((factorial[n - r] * factorial[r]) % mod, mod)) % mod;
		}
	}

}
