#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, len;
char ch[2505][5005];
char st[5005];
int pos[5];
int numb[5005];
int f[130];
int h[130];
int check() {
  int sign = 0;
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= len; i++) {
    f[st[i]]++;
    if (f[st[i]] >= 2) sign = 1;
  }
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    memcpy(h, f, sizeof(h));
    for (int j = 1; j <= len; j++) {
      if (st[j] != ch[i][j]) cnt++;
      h[ch[i][j]]--;
    }
    for (int j = 1; j <= 128; j++)
      if (h[j] != 0) return 0;
    if (cnt > 2 || cnt == 1) return 0;
    if (cnt == 0 && sign == 0) return 0;
  }
  return 1;
}
int cal(int x, int y) {
  int cnt = 0;
  for (int i = 1; i <= len; i++)
    if (ch[x][i] != ch[y][i]) pos[++cnt] = i;
  return cnt;
}
int main() {
  n = read();
  len = read();
  for (int i = 1; i <= n; i++) scanf("%s", ch[i] + 1);
  if (n == 1) {
    swap(ch[1][len - 1], ch[1][len]);
    printf("%s", ch[1] + 1);
    return 0;
  }
  int e = 1;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int r = cal(i, j);
      if (r > 4) {
        printf("-1");
        return 0;
      } else if (r <= 4 && r > 0) {
        for (int k = 1; k <= len; k++) st[k] = ch[i][k];
        if (check()) {
          printf("%s", st + 1);
          return 0;
        }
        for (int k = 1; k < r; k++) {
          for (int l = i + 1; l <= r; l++) {
            swap(st[pos[k]], st[pos[l]]);
            if (check()) {
              printf("%s", st + 1);
              return 0;
            }
            swap(st[pos[k]], st[pos[l]]);
          }
        }
        if (r == 2) {
          for (int k = 1; k <= len; k++) {
            if (k == pos[1] || k == pos[2])
              continue;
            else {
              for (int l = 1; l <= 2; l++) {
                swap(st[k], st[pos[l]]);
                if (check()) {
                  printf("%s", st + 1);
                  return 0;
                }
                swap(st[k], st[pos[l]]);
              }
            }
          }
        }
        e = 0;
        break;
      } else if (r == 0) {
        for (int k = 1; k <= len; k++) st[k] = ch[i][k];
        if (check()) {
          printf("%s", st + 1);
          return 0;
        }
        int sign = 0;
        for (int k = j + 1; k <= n; k++)
          if (cal(i, k)) {
            sign = k;
            break;
          }
        if (sign == 0) {
          swap(ch[i][len - 1], ch[i][len]);
          printf("%s", ch[i] + 1);
          return 0;
        } else {
          j = sign - 1;
          continue;
        }
        e = 0;
        break;
      }
    }
    if (e == 0) break;
  }
  printf("-1");
  return 0;
}
