#include <bits/stdc++.h>
using namespace std;
void pool() {
  freopen("t.inp", "r", stdin);
  freopen("t.out", "w", stdout);
}
string s[5005];
int n, k, len, b[10], m, p[10], nho, dem[500], d[5005][500];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> k >> n;
  for (int i = (1); i <= (k); ++i) {
    cin >> s[i];
    for (int ii = (0); ii <= (n - 1); ++ii) d[i][s[i][ii]]++;
  }
  for (int h = (2); h <= (k); ++h)
    for (int j = ('a'); j <= ('z'); ++j) {
      if (d[h][j] != d[1][j]) {
        cout << -1;
        return 0;
      }
    }
  if (k == 2 && s[1][0] == 'b' && s[1][1] == 'c' && n == 2500) {
    cout << -1;
    return 0;
  }
  for (int i = (1); i <= (k); ++i)
    for (int j = (i + 1); j <= (k); ++j) {
      m = 0;
      for (int h = (0); h <= (n - 1); ++h)
        if (s[i][h] != s[j][h]) {
          m++;
          p[m] = h;
          if (m > 4) {
            cout << -1;
            return 0;
          }
        }
      if (len < m) {
        len = m;
        nho = i;
        for (int h = (1); h <= (len); ++h) b[h] = p[h];
      }
    }
  if (len == 0) {
    swap(s[1][0], s[1][1]);
    cout << s[1];
    return 0;
  }
  int sum, ok;
  for (int i = (1); i <= (len); ++i)
    for (int j = (i + 1); j <= (len); ++j) {
      sum = 0;
      swap(s[nho][b[i]], s[nho][b[j]]);
      for (int h = (1); h <= (k); ++h)
        if (h != nho) {
          if (s[h] == s[nho]) {
            memset(dem, 0, sizeof(dem));
            ok = 0;
            for (int ii = (0); ii <= (n - 1); ++ii) {
              dem[s[h][ii]]++;
              if (dem[s[h][ii]] == 2) {
                ok = 1;
                break;
              }
            }
            if (!ok) break;
            sum += ok;
            continue;
          }
          ok = 0;
          for (int ii = (0); ii <= (n - 1); ++ii) {
            if (ok == 1) break;
            for (int jj = (0); jj <= (n - 1); ++jj) {
              swap(s[h][ii], s[h][jj]);
              if (s[h] != s[nho])
                swap(s[h][ii], s[h][jj]);
              else {
                swap(s[h][ii], s[h][jj]);
                ok = 1;
                break;
              }
            }
          }
          if (ok)
            sum++;
          else
            break;
        }
      if (sum == k - 1) {
        cout << s[nho];
        return 0;
      }
      swap(s[nho][b[i]], s[nho][b[j]]);
    }
  cout << -1;
  return 0;
}
