#include <bits/stdc++.h>
using namespace std;
char A[2510][5010];
int dif[2510][10];
int cnt[2510];
int num[30];
int tmp[30];
int hv[2510];
inline int judge(int x, int y, int z) {
  int clt = 0;
  int hvx = 0, hvy = 0;
  for (int i = 1; i <= cnt[z]; i++) {
    if (dif[z][i] == x) hvx = 1;
    if (dif[z][i] == y) hvy = 1;
  }
  if (!hvx && !hvy) {
    clt += (A[1][y] != A[z][x]);
    clt += (A[1][x] != A[z][y]);
  }
  if (hvx && !hvy) {
    clt -= (A[1][y] == A[z][x]);
    clt += (A[1][x] != A[z][y]);
  }
  if (hvy && !hvx) {
    clt -= (A[1][x] == A[z][y]);
    clt += (A[1][y] != A[z][x]);
  }
  if (hvy && hvx) {
    clt -= (A[1][x] == A[z][y]);
    clt -= (A[1][y] == A[z][x]);
  }
  return cnt[z] + clt;
}
int main() {
  int k, n;
  scanf("%d %d", &k, &n);
  for (int i = 1; i <= k; i++) {
    memset(tmp, 0, sizeof(tmp));
    for (int j = 1; j <= n; j++) {
      cin >> A[i][j];
      if (i == 1)
        num[A[i][j] - 'a']++;
      else
        tmp[A[i][j] - 'a']++;
    }
    int ok = 1;
    if (i != 1) {
      for (int j = 0; j < 26; j++) {
        if (tmp[j] != num[j]) ok = 0;
        if (tmp[j] > 1) hv[i] = 1;
      }
      if (!ok) {
        puts("-1");
        return 0;
      }
    }
  }
  for (int i = 2; i <= k; i++) {
    for (int j = 1; j <= n; j++)
      if (A[1][j] != A[i][j]) dif[i][++cnt[i]] = j;
    if (cnt[i] > 4) {
      puts("-1");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      int ok = 1;
      for (int l = 2; l <= k; l++) {
        if (judge(i, j, l) > 2 || (judge(i, j, l) == 0 && !hv[l])) ok = 0;
      }
      if (ok) {
        swap(A[1][i], A[1][j]);
        for (int l = 1; l <= n; l++) printf("%c", A[1][l]);
        return 0;
      }
    }
  puts("-1");
  return 0;
}
