#include <bits/stdc++.h>
using namespace std;
void print(vector<long long> &a) {
  for (int i = 0; i < a.size(); i++) cout << a[i] << " \n"[i == a.size() - 1];
}
void print(vector<int> &a) {
  for (int i = 0; i < a.size(); i++) cout << a[i] << " \n"[i == a.size() - 1];
}
void print(int a[], int l, int r) {
  for (int i = l; i <= r; i++) cout << a[i] << " \n"[i == r];
}
void print(long long a[], int l, int r) {
  for (int i = l; i <= r; i++) cout << a[i] << " \n"[i == r];
}
long long qpow(long long x, long long y) {
  long long temp = x;
  long long ans = 1;
  while (y) {
    if (y & 1) ans = (ans * temp);
    temp = (temp * temp);
    y >>= 1;
  }
  return ans;
}
long long qpow(long long x, long long y, long long MOD) {
  long long temp = x;
  long long ans = 1;
  while (y) {
    if (y & 1) ans = (ans * temp) % MOD;
    temp = (temp * temp) % MOD;
    y >>= 1;
  }
  return ans;
}
void INIT() {}
string s[5005];
bool has_same[5005];
int pos[200];
int ppos[5005][20];
int len;
int n, m;
int bb[5005];
bool check_Len(string now);
bool check(string now) {
  int l = 0;
  for (int k = 0; k < n; k++) {
    l = 0;
    set<int> st;
    for (int i = 0; i < len; i++) st.insert(pos[i]);
    for (int i = 1; i <= ppos[k][0]; i++) st.insert(ppos[k][i]);
    for (auto i : st)
      if (now[i] != s[k][i]) bb[l++] = i;
    if (!(l == 2 || l == 0 && has_same[0])) return false;
    if (l == 0) continue;
    int p1 = bb[0];
    int p2 = bb[1];
    if (now[p1] != s[k][p2] || now[p2] != s[k][p1]) return false;
  }
  return true;
}
bool check_Len(string now) {
  int l = 0;
  for (int k = 0; k < n; k++) {
    l = 0;
    for (int i = 0; i < m; i++)
      if (now[i] != s[k][i]) {
        bb[l++] = i;
      }
    if (!(l == 2 || l == 0 && has_same[0])) return false;
    if (l == 0) continue;
    int p1 = bb[0];
    int p2 = bb[1];
    if (now[p1] != s[k][p2] || now[p2] != s[k][p1]) return false;
  }
  return true;
}
void solve() {
  cin >> n >> m;
  memset(has_same, false, sizeof(has_same));
  ;
  int num[30];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    memset(num, 0, sizeof(num));
    ;
    for (int j = 0; j < m; j++) {
      num[s[i][j] - 'a']++;
      if (num[s[i][j] - 'a'] >= 2) has_same[i] = true;
    }
    if (i != 0) {
      for (int j = 0; j < m; j++) {
        if (s[0][j] != s[i][j]) {
          ppos[i][++ppos[i][0]] = j;
          if (ppos[i][0] > 4) {
            cout << "-1"
                 << "\n";
            return;
          }
        }
      }
    }
  }
  if (n == 1) {
    swap(s[0][0], s[0][1]);
    cout << s[0] << "\n";
    return;
  }
  int P[5] = {0, 1, 2, 3, 4};
  string now = "";
  set<int> xx;
  if (m <= 4) {
    for (int i = 0; i <= m - 1; i++) {
      now = now + s[0][i];
      pos[len++] = i;
    }
  } else {
    for (int i = 0; i <= m - 1; i++) {
      now = now + s[0][i];
    }
    len = 0;
    for (int i = 1; i < n; i++) {
      xx.clear();
      for (int j = 0; j < m; j++) {
        if (s[0][j] != s[i][j]) {
          xx.insert(j);
        }
      }
      if (xx.size() > len) {
        len = 0;
        for (auto i : xx) {
          pos[len++] = i;
        }
      }
    }
  }
  if (len > 4) {
    cout << "-1"
         << "\n";
    return;
  }
  do {
    for (int i = 0; i < len; i++) now[pos[i]] = s[0][pos[P[i]]];
    if (false)
      cout << "DEBUG "
           << "now"
           << ": " << now << "\n";
    if (check(now)) {
      if (check_Len(now)) {
        cout << now << "\n";
        return;
      }
    }
  } while (next_permutation(P, P + len));
  cout << -1 << "\n";
  return;
}
int main() {
  solve();
  return 0;
}
