#include <bits/stdc++.h>
using namespace std;
int val[10001];
int ham(string &a, string &b) {
  int ret = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != b[i]) ret++;
  }
  return ret;
}
string second[10001];
int fa[26] = {0};
int fb[26] = {0};
bool rep = 0;
bool check(string &a, string &b) {
  for (int i = 0; i < 26; i++) fa[i] = 0;
  for (int i = 0; i < 26; i++) fb[i] = 0;
  for (auto x : a) {
    fa[x - 'a']++;
    if (fa[x - 'a'] > 1) rep = 1;
  }
  for (auto x : b) {
    fb[x - 'a']++;
    if (fb[x - 'a'] > 1) rep = 1;
  }
  for (int i = 0; i < 26; i++) {
    if (fa[i] != fb[i]) {
      return 0;
    }
  }
  return 1;
}
int main() {
  int k, n;
  cin >> k >> n;
  for (int i = 0; i < k; i++) {
    cin >> second[i];
  }
  for (int i = 0; i < k; i++) {
    if (!check(second[i], second[0])) {
      cout << -1;
      return 0;
    }
    val[i] = ham(second[i], second[0]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      bool ok = 1;
      for (int _ = 0; _ < k; _++) {
        int cur = val[_] - (int)(second[_][i] != second[0][i]) -
                  (int)(second[_][j] != second[0][j]) +
                  (int)(second[_][i] != second[0][j]) +
                  (int)(second[_][j] != second[0][i]);
        if (cur > 2 || (cur == 0 && rep == 0)) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        swap(second[0][i], second[0][j]);
        cout << second[0];
        return 0;
      }
    }
  }
  cout << -1;
}
