#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int maxm = maxn * 2;
const int inf = 0x3f3f3f3f;
const int MOD = 2520;
char s[2505][5005];
int diff[2505];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<int> f(26), g(26);
  int k, n;
  cin >> k >> n;
  cin >> (s[1] + 1);
  int p = 0;
  for (int i = 1; i <= n; i++) g[s[1][i] - 'a']++;
  for (int i = 0; i < 26; i++)
    if (g[i] > 1) p = 1;
  for (int i = 2; i <= k; i++) {
    cin >> (s[i] + 1);
    for (int j = 0; j < 26; j++) f[j] = 0;
    for (int j = 1; j <= n; j++) f[s[i][j] - 'a']++;
    if (f != g) {
      puts("-1");
      return 0;
    }
    for (int j = 1; j <= n; j++)
      if (s[i][j] != s[1][j]) diff[i]++;
  }
  int p1 = 0, p2 = 0;
  for (p1 = 1; p1 <= n; p1++) {
    for (p2 = p1 + 1; p2 <= n; p2++) {
      int flag = 1;
      for (int i = 2; i <= k; i++) {
        int num = diff[i];
        if (s[1][p1] == s[i][p1]) num++;
        if (s[1][p1] == s[i][p2]) num--;
        if (s[1][p2] == s[i][p1]) num--;
        if (s[1][p2] == s[i][p2]) num++;
        if (!((p && num == 0) || num == 2)) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        swap(s[1][p1], s[1][p2]);
        cout << (s[1] + 1) << '\n';
        return 0;
      }
    }
  }
  puts("-1");
  return 0;
}
