#include <bits/stdc++.h>
using namespace std;
string s[3000];
int dif[3000];
int num[26], num2[26];
int main() {
  int k, n, f = 0;
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= k; ++i) cin >> s[i];
  for (int i = 0; i < n; i++) num[s[1][i] - 'a']++;
  for (int i = 0; i < 26; i++) f += (num[i] > 1);
  for (int i = 2; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      num2[s[i][j] - 'a']++;
      dif[i] += (s[i][j] != s[1][j]);
    }
    for (int j = 0; j < 26; j++) {
      if (num[j] != num2[j]) {
        printf("-1\n");
        return 0;
      }
      num2[j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int ok = 1;
      for (int z = 2; z <= k; z++) {
        int cnt = dif[z];
        cnt -= (s[1][i] != s[z][i]);
        cnt -= (s[1][j] != s[z][j]);
        cnt += (s[1][i] != s[z][j]);
        cnt += (s[1][j] != s[z][i]);
        if ((!cnt && f) || cnt == 2) ok++;
      }
      if (ok == k) {
        swap(s[1][i], s[1][j]);
        cout << s[1] << endl;
        return 0;
      }
    }
  }
  printf("-1\n");
  return 0;
}
