#include <bits/stdc++.h>
using namespace std;
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
bool check(vector<string> &a, string &s, int pos = -1) {
  for (int j = 0; j < a.size(); ++j) {
    string c = a[j];
    if (j == pos) continue;
    int cnt = 0, pos1 = -1, pos2 = -1;
    map<char, int> q;
    int maxx = 0;
    for (int i = 0; i < s.size(); ++i) {
      ++q[c[i]];
      maxx = max(maxx, q[c[i]]);
      if (s[i] != c[i]) {
        ++cnt;
        if (cnt == 1) pos1 = i;
        if (cnt == 2) pos2 = i;
      }
    }
    if (cnt != 2 && cnt != 0) return false;
    if (cnt == 0 && maxx <= 1) return false;
    string a1 = a[j], a2 = s;
    sort(a1.begin(), a1.end());
    sort(a2.begin(), a2.end());
    if (a1 != a2) return false;
  }
  return true;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  int pos1 = -1, pos2 = -1;
  vector<string> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    for (int j = 0; j < i; ++j) {
      if (a[i] != a[j]) {
        pos1 = i;
        pos2 = j;
      }
    }
  }
  if (pos1 == -1) {
    swap(a[0][0], a[0][1]);
    cout << a[0] << endl;
    return;
  } else {
    vector<int> poses;
    for (int i = 0; i < k; ++i) {
      if (a[pos1][i] != a[pos2][i]) {
        poses.push_back(i);
      }
    }
    if (poses.size() > 4) {
      cout << -1 << endl;
      return;
    } else {
      for (int i = 0; i < poses.size(); ++i) {
        int cur = poses[i];
        for (int j = 0; j < k; ++j) {
          if (cur != j) {
            swap(a[pos1][cur], a[pos1][j]);
            if (check(a, a[pos1], pos1)) {
              cout << a[pos1] << endl;
              return;
            }
            swap(a[pos1][cur], a[pos1][j]);
          }
        }
      }
    }
    cout << -1 << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(15);
  int t;
  if (IS_ONE_TEST)
    t = 1;
  else
    cin >> t;
  while (t-- > 0) {
    solve();
  }
}
