#include <bits/stdc++.h>
using namespace std;
int n, m, d[2509];
char s[2509][5009];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", &s[i]);
  int cnt[30] = {0}, vis[30] = {0};
  for (int i = 0; i < m; i++) cnt[s[0][i] - 'a']++;
  bool same = 0, flag = 1;
  for (int i = 0; i < 26; i++) same |= (cnt[i] > 1);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < m; j++) {
      d[i] += (s[0][j] != s[i][j]);
      vis[s[i][j] - 'a']++;
    }
    for (int j = 0; j < 26; j++) {
      if (vis[j] != cnt[j]) flag = 0;
      vis[j] = 0;
    }
    if (!flag) return 0 * puts("-1");
  }
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      flag = 1;
      for (int k = 1; k < n; k++) {
        int res = d[k] - (s[0][i] != s[k][i]) - (s[0][j] != s[k][j]) +
                  (s[0][i] != s[k][j]) + (s[0][j] != s[k][i]);
        if (!(res == 2 || (res == 0 && same))) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        swap(s[0][i], s[0][j]);
        printf("%s\n", s[0]);
        return 0;
      }
    }
  }
  if (!flag) puts("-1");
  return 0;
}
