#include <bits/stdc++.h>
using namespace std;
const int MAX = 5005;
string ar[MAX];
int cnt[MAX], n, sz, freq[MAX], cop[MAX];
bool rep;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> sz;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (!i) {
      for (int idx = 0; idx < sz; idx++) {
        freq[ar[i][idx]]++;
        if (freq[ar[i][idx]] > 1) rep = true;
      }
    } else {
      memset(cop, 0, sizeof(cop));
      for (int idx = 0; idx < sz; idx++) {
        cop[ar[i][idx]]++;
        if (ar[i][idx] != ar[0][idx]) cnt[i]++;
      }
      for (int idx = 0; idx < MAX; idx++) {
        if (freq[idx] != cop[idx]) {
          cout << "-1\n";
          return 0;
        }
      }
    }
  }
  for (int i = 0; i < sz; i++)
    for (int j = i + 1; j < sz; j++) {
      int mx = 0;
      int mn = MAX;
      for (int idx = 0; idx < n; idx++) {
        if (ar[0][i] != ar[idx][i]) cnt[idx]--;
        if (ar[0][j] != ar[idx][j]) cnt[idx]--;
        if (ar[0][i] != ar[idx][j]) cnt[idx]++;
        if (ar[0][j] != ar[idx][i]) cnt[idx]++;
        mx = max(mx, cnt[idx]);
        mn = min(mn, cnt[idx]);
        if (ar[0][i] != ar[idx][i]) cnt[idx]++;
        if (ar[0][j] != ar[idx][j]) cnt[idx]++;
        if (ar[0][i] != ar[idx][j]) cnt[idx]--;
        if (ar[0][j] != ar[idx][i]) cnt[idx]--;
      }
      if ((rep || mn == 2) && (mx <= 2)) {
        swap(ar[0][i], ar[0][j]);
        cout << ar[0] << "\n";
        return 0;
      }
    }
  cout << "-1\n";
}
