#include <bits/stdc++.h>
using namespace std;
inline int readi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n;
bool twosame = 0;
set<string> S;
bool chk(string A) {
  for (string s : S) {
    int dif = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] != A[i]) dif++;
    }
    if ((dif != 0) && (dif != 2)) return 0;
  }
  if (!twosame) {
    for (string s : S) {
      if (s == A) return 0;
    }
  }
  return 1;
}
int main() {
  int k = readi();
  n = readi();
  for (int i = 0; i < k; i++) {
    string s;
    cin >> s;
    S.insert(s);
  }
  string sorted;
  for (string s : S) {
    if (sorted.size() == 0) {
      sorted = s;
      sort(sorted.begin(), sorted.end());
      for (int i = 1; i < n; i++) {
        if (sorted[i] == sorted[i - 1]) twosame = 1;
      }
    }
    string tmp = s;
    sort(tmp.begin(), tmp.end());
    if (tmp != sorted) {
      puts("-1");
      return 0;
    }
  }
  if (S.size() == 1) {
    string tmp = *S.begin();
    for (int i = 1; i < n; i++) {
      if (tmp[i] != tmp[0]) {
        swap(tmp[i], tmp[0]);
        break;
      }
    }
    cout << tmp << endl;
    return 0;
  }
  auto t = clock();
  string A = *S.begin();
  auto it = S.begin();
asdfasdf:
  ++it;
  if (it == S.end()) return puts("-1") * 0;
  string B = *it;
  vector<int> diff;
  diff.clear();
  for (int i = 0; i < n; i++) {
    if (A[i] != B[i]) diff.push_back(i);
  }
  if (diff.size() > 4) {
    puts("-1");
    return 0;
  }
  if (diff.size() == 1) {
    puts("-1");
    return 0;
  }
  if (diff.size() == 2) {
    if (chk(A)) {
      cout << A << endl;
      return 0;
    }
    if (chk(B)) {
      cout << B << endl;
      return 0;
    }
    if ((double)(clock() - t) / CLOCKS_PER_SEC > 0.5) return puts("-1") * 0;
    goto asdfasdf;
    puts("-1");
    return 0;
  }
  if (diff.size() == 3) {
    string tmp = A;
    swap(tmp[diff[0]], tmp[diff[1]]);
    if (chk(tmp)) {
      cout << tmp << endl;
      return 0;
    }
    swap(tmp[diff[0]], tmp[diff[1]]);
    swap(tmp[diff[0]], tmp[diff[2]]);
    if (chk(tmp)) {
      cout << tmp << endl;
      return 0;
    }
    swap(tmp[diff[0]], tmp[diff[2]]);
    swap(tmp[diff[2]], tmp[diff[1]]);
    if (chk(tmp)) {
      cout << tmp << endl;
      return 0;
    }
    swap(tmp[diff[2]], tmp[diff[1]]);
    puts("-1");
    return 0;
  }
  if (diff.size() == 4) {
    for (int i = 1; i < 4; i++) {
      string tmp = A;
      swap(tmp[diff[0]], tmp[diff[i]]);
      set<int> asdf = {1, 2, 3};
      asdf.erase(i);
      swap(tmp[diff[*asdf.begin()]], tmp[diff[*next(asdf.begin())]]);
      if (tmp != B) continue;
      swap(tmp[diff[*asdf.begin()]], tmp[diff[*next(asdf.begin())]]);
      if (chk(tmp)) {
        cout << tmp << endl;
        return 0;
      }
      swap(tmp[diff[*asdf.begin()]], tmp[diff[*next(asdf.begin())]]);
      swap(tmp[diff[0]], tmp[diff[i]]);
      if (chk(tmp)) {
        cout << tmp << endl;
        return 0;
      }
    }
    puts("-1");
    return 0;
  }
  return 0;
}
