#include <bits/stdc++.h>
using namespace std;
string s[1000010];
int n, k, vis[1000010], d[1000010];
map<int, int> q[1000010];
int main() {
  cin >> k >> n;
  for (int i = 1; i <= k; i++) {
    cin >> s[i];
    for (auto t : s[i])
      if (++q[i][t] > 1) vis[i] = 1;
    if (q[i] != q[1]) return puts("-1"), 0;
  }
  if (k == 1) {
    swap(s[1][0], s[1][1]);
    cout << s[1] << endl;
    return 0;
  }
  for (int i = 2; i <= k; i++)
    for (int j = 0; j < n; j++) d[i] += s[1][j] != s[i][j];
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      int ok = 1;
      for (int kk = 2; kk <= k; kk++) {
        int t = d[kk];
        d[kk] -= s[1][i] != s[kk][i];
        d[kk] -= s[1][j] != s[kk][j];
        d[kk] += s[1][j] != s[kk][i];
        d[kk] += s[1][i] != s[kk][j];
        if (d[kk] == 1)
          ok = 0;
        else if (d[kk] == 0 && !vis[kk])
          ok = 0;
        else if (d[kk] > 2)
          ok = 0;
        d[kk] = t;
      }
      if (ok) {
        swap(s[1][i], s[1][j]);
        cout << s[1] << endl;
        return 0;
      }
    }
  puts("-1");
}
