#include <bits/stdc++.h>
using namespace std;
char s[2505][5005];
int a[5000];
int c1[30], c2[30];
int dif[2505];
int main() {
  int k, n;
  scanf("%d%d", &k, &n);
  scanf("%s", s[0]);
  bool flag = false;
  for (int i = 0; i < n; ++i) {
    c1[s[0][i] - 'a']++;
    if (c1[s[0][i] - 'a'] > 1) flag = true;
  }
  for (int i = 1; i < k; ++i) {
    scanf("%s", s[i]);
    memset(c2, 0, sizeof(c2));
    for (int j = 0; j < n; ++j) {
      c2[s[i][j] - 'a']++;
      if (s[i][j] != s[0][j]) dif[i]++;
    }
    if (dif[i] > 4) {
      cout << "-1\n";
      return 0;
    }
    for (int j = 0; j < 26; ++j) {
      if (c1[j] != c2[j]) {
        cout << "-1\n";
        return 0;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      bool ok = true;
      for (int l = 1; l < k; ++l) {
        a[l] = dif[l];
        a[l] -= (s[0][i] != s[l][i]);
        a[l] -= (s[0][j] != s[l][j]);
        a[l] += (s[0][i] != s[l][j]);
        a[l] += (s[0][j] != s[l][i]);
        if ((a[l] == 0 && flag) || a[l] == 2) continue;
        ok = false;
        break;
      }
      if (ok) {
        swap(s[0][i], s[0][j]);
        cout << s[0] << endl;
        return 0;
      }
    }
  }
  cout << "-1\n";
  return 0;
}
