#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const int64_t LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
template <typename T>
T gcd(T a, T b) {
  return (a == 0) ? b : gcd(b % a, a);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
bool p_comp_fs(const pair<int64_t, int64_t> p1,
               const pair<int64_t, int64_t> p2) {
  return p1.first < p2.first;
};
bool p_comp_fg(const pair<int64_t, int64_t> p1,
               const pair<int64_t, int64_t> p2) {
  return p1.first > p2.first;
};
bool p_comp_ss(const pair<int64_t, int64_t> p1,
               const pair<int64_t, int64_t> p2) {
  return p1.second < p2.second;
};
bool p_comp_sg(const pair<int64_t, int64_t> p1,
               const pair<int64_t, int64_t> p2) {
  return p1.second > p2.second;
};
template <typename T>
vector<T> uniquen(vector<T> vec) {
  sort((vec).begin(), (vec).end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;
}
inline int64_t popcnt(int64_t x) {
  return __builtin_popcountll((unsigned long long)x);
};
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename Monoid>
struct SegmentTree {
  using F = function<Monoid(Monoid, Monoid)>;
  int64_t sz;
  vector<Monoid> seg;
  const F f;
  const Monoid M1;
  SegmentTree(int64_t n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while (sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
  void set(int64_t k, const Monoid &x) { seg[k + sz] = x; }
  void build() {
    for (int64_t k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
  void update(int64_t k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while (k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
  Monoid query(int64_t a, int64_t b) {
    Monoid L = M1, R = M1;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = f(L, seg[a++]);
      if (b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
  Monoid operator[](const int64_t &k) const { return seg[k + sz]; }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t K, N;
  cin >> K >> N;
  string S;
  cin >> S;
  vector<string> T(K - 1);
  for (int64_t i = 0; i < K - 1; i++) cin >> T[i];
  map<char, int64_t> cnt;
  for (int64_t i = 0; i < N; i++) cnt[S[i]]++;
  bool can_be_zero = false;
  for (auto it = cnt.begin(); it != cnt.end(); it++)
    if (it->second >= 2) can_be_zero = true;
  for (int64_t k = 0; k < K - 1; k++) {
    map<char, int64_t> cnt_t;
    for (int64_t i = 0; i < N; i++) cnt_t[T[k][i]]++;
    for (auto it = cnt_t.begin(); it != cnt_t.end(); it++) {
      if (cnt[it->first] != it->second) {
        cout << -1 << endstr;
        return 0;
      }
    }
  }
  vector<int64_t> Dorg(K - 1, 0);
  for (int64_t i = 0; i < K - 1; i++) {
    for (int64_t idx = 0; idx < N; idx++) {
      if (S[idx] != T[i][idx]) {
        Dorg[i]++;
      }
    }
  }
  for (int64_t l = 0; l < N; l++)
    for (int64_t r = (l + 1); r < N + 1; r++) {
      auto D = Dorg;
      char nl = S[r], nr = S[l], pl = S[l], pr = S[r];
      for (int64_t k = 0; k < K - 1; k++) {
        if (T[k][l] != pl && T[k][l] == nl) D[k]--;
        if (T[k][l] == pl && T[k][l] != nl) D[k]++;
        if (T[k][r] != pr && T[k][r] == nr) D[k]--;
        if (T[k][r] == pr && T[k][r] != nr) D[k]++;
      }
      bool ok = true;
      for (int64_t k = 0; k < K - 1; k++) {
        if (D[k] != 2) {
          if (D[k] == 0 && can_be_zero) {
          } else {
            ok = false;
            break;
          }
        }
      }
      if (ok) {
        swap(S[l], S[r]);
        cout << S << endstr;
        return 0;
      }
    }
  cout << -1 << endstr;
  return 0;
}
