#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int INF = 0x3f3f3f3f;
const int maxn = 5005;
string s[maxn], ans;
int ham[maxn], num1[30], num2[30];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int flag = 0;
  for (int i = 1; i <= n; i++) cin >> s[i];
  memset(ham, 0, sizeof(ham));
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (s[1][j] != s[i][j]) ham[i]++;
    }
  }
  memset(num1, 0, sizeof(num1));
  for (int i = 0; i < k; i++) num1[s[1][i] - 'a']++;
  for (int i = 0; i < 26; i++)
    if (num1[i] > 1) flag = 1;
  for (int i = 2; i <= n; i++) {
    memset(num2, 0, sizeof(num2));
    for (int j = 0; j < k; j++) {
      num2[s[i][j] - 'a']++;
    }
    for (int j = 0; j < 26; j++) {
      if (num1[j] != num2[j]) {
        cout << -1;
        return 0;
      }
    }
  }
  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++) {
      int num = 0;
      for (int k = 2; k <= n; k++) {
        int cnt = ham[k];
        cnt -= (s[1][i] != s[k][i]);
        cnt -= (s[1][j] != s[k][j]);
        cnt += (s[1][i] != s[k][j]);
        cnt += (s[1][j] != s[k][i]);
        if ((cnt == 0 && flag) || cnt == 2)
          num++;
        else
          break;
      }
      if (num == n - 1) {
        swap(s[1][i], s[1][j]);
        cout << s[1];
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
