#include <bits/stdc++.h>
using namespace std;
int k, n, dis[2505];
string s[2505];
bool twochars[2505];
map<char, int> mp[2505];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    for (auto c : s[i])
      if (++mp[i][c] > 1) twochars[i] = true;
    if (mp[i] != mp[0]) return cout << -1, 0;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < k; ++j) dis[i] += (s[0][j] != s[i][j]);
  for (int x = 0; x < k; ++x)
    for (int y = x + 1; y < k; ++y) {
      for (int i = 1; i < n; ++i)
        if (dis[i] - (s[i][x] != s[0][x]) + (s[i][x] != s[0][y]) -
                    (s[i][y] != s[0][y]) + (s[i][y] != s[0][x]) >
                2 ||
            dis[i] - (s[i][x] != s[0][x]) + (s[i][x] != s[0][y]) -
                        (s[i][y] != s[0][y]) + (s[i][y] != s[0][x]) ==
                    0 &&
                !twochars[i])
          goto end;
      swap(s[0][x], s[0][y]);
      return cout << s[0], 0;
    end:;
    }
  cout << -1, 0;
}
