#include <bits/stdc++.h>
using namespace std;
const int mn = 6005;
string s[mn];
vector<string> str;
int main() {
  int k, n;
  cin >> k >> n;
  for (int i = 0; i < k; i++) {
    cin >> s[i];
  }
  bool f = 0;
  for (int i = 1; i < k; i++) {
    if (s[i] != s[i - 1]) {
      f = 1;
    }
  }
  if (f == 0) {
    if (n == 2) {
      cout << s[0][1] << s[0][0];
    } else {
      cout << s[0][1] << s[0][0] << s[0].substr(2, n - 2);
    }
    return 0;
  }
  string a = "", b = "";
  for (int i = 1; i < k; i++) {
    if (s[i] != s[0]) {
      b = s[i];
    }
  }
  a = s[0];
  int rem = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      rem = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == rem) continue;
    swap(a[i], a[rem]);
    str.push_back(a);
    swap(a[i], a[rem]);
    swap(b[i], b[rem]);
    str.push_back(b);
    swap(b[i], b[rem]);
  }
  int raz[2];
  unordered_map<char, int> mp;
  for (int i = 0; i < str.size(); i++) {
    string t = str[i];
    bool can = 0;
    for (int j = 0; j < min(27, (int)t.size()); j++) {
      mp[t[j]]++;
      if (mp[t[j]] >= 2) {
        can = 1;
      }
    }
    for (int j = 0; j < 26; j++) {
      mp[char(j + 'a')] = 0;
    }
    int cnt = 0;
    bool f2 = 0;
    for (int j = 0; j < k; j++) {
      cnt = 0;
      for (int l = 0; l < n; l++) {
        if (t[l] != s[j][l]) {
          cnt++;
          raz[cnt % 2] = l;
        }
        if (l != 0) {
        }
      }
      if (cnt == 0 || cnt == 2) {
        if ((cnt == 2)) {
          if ((s[j][raz[1]] == t[raz[0]]) && (t[raz[1]] == s[j][raz[0]])) {
          } else {
            f2 = 1;
            break;
          }
        }
        if (cnt == 0) {
          if (!can) {
            f2 = 1;
            break;
          }
        }
      } else {
        f2 = 1;
        break;
      }
    }
    if (f2 == 0) {
      cout << t;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
