#include <bits/stdc++.h>
using namespace std;
inline void boost() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const long long maxn = 5e3 + 123;
const long long inf = 1e9 + 123;
const long long linf = 1e18 + 123;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double pi = acos(-1);
int dx[8] = {0, 1, -1, 0, 1, -1, 1, -1};
int dy[8] = {1, 0, 0, -1, 1, 1, -1, -1};
bool self[maxn];
string s[maxn];
int a[maxn][30];
vector<int> v;
int n, k;
set<string> second;
bool check(string t) {
  for (int i = 1; i <= n; ++i) {
    int a = -1, b = -1;
    for (int j = 0; j < k; ++j) {
      if (t[j] != s[i][j]) {
        if (a == -1) {
          a = j;
        } else if (b == -1) {
          b = j;
        } else {
          return 0;
        }
      }
    }
    if (a == -1) {
      if (!self[i]) {
        return 0;
      }
    } else {
      if (b == -1) {
        return 0;
      }
      if (t[a] != s[i][b] || t[b] != s[i][a]) {
        return 0;
      }
    }
  }
  return 1;
}
int main() {
  boost();
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  int p = 2;
  while (p <= n && s[1] == s[p]) {
    ++p;
  }
  if (p > n) {
    swap(s[1][0], s[1][1]);
    cout << s[1];
    return 0;
  }
  vector<int> v;
  for (int i = 0; i < k; ++i) {
    if (s[1][i] != s[p][i]) {
      v.push_back(i);
    }
  }
  if (v.size() > 4) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    for (int a = 0; a < k; ++a) {
      for (int b = a + 1; b < k; ++b) {
        if (s[i][a] == s[i][b]) {
          self[i] = 1;
        }
      }
    }
  }
  if (self[1] && check(s[1])) {
    cout << s[1] << endl;
    return 0;
  }
  for (int a : v) {
    for (int b = 0; b < k; ++b) {
      if (a == b) {
        continue;
      }
      string tmp = s[1];
      swap(tmp[a], tmp[b]);
      if (check(tmp)) {
        cout << tmp << endl;
        return 0;
      }
    }
  }
  cout << "-1";
  exit(0);
}
