#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int k, n;
char str[maxn][maxn];
int f;
bool check(char t[], int pos) {
  f = 0;
  int vis[26] = {};
  for (int i = 0; i < n; i++) {
    if (++vis[t[i] - 'a'] > 1) {
      f = 1;
    }
  }
  for (int i = 0; i < k; i++) {
    if (i == pos) {
      continue;
    }
    int p1 = -1, p2 = -1;
    for (int j = 0; j < n; j++) {
      if (t[j] == str[i][j]) {
        continue;
      }
      if (p1 == -1) {
        p1 = j;
      } else if (p2 == -1) {
        p2 = j;
      } else {
        return false;
      }
    }
    if (p1 == -1 && p2 == -1 && f) {
      continue;
    }
    if (p1 == -1 || p2 == -1) {
      return false;
    }
    if (p1 != -1) {
      if (t[p2] != str[i][p1] || t[p1] != str[i][p2]) {
        return false;
      }
    }
  }
  return true;
}
void swp(char *str, int i, int j) {
  char t = str[i];
  str[i] = str[j];
  str[j] = t;
}
int main() {
  scanf("%d%d", &k, &n);
  scanf("%s", str[0]);
  int pos = -1;
  for (int i = 1; i < k; i++) {
    scanf("%s", str[i]);
    if (strcmp(str[0], str[i]) != 0 && pos == -1) {
      pos = i;
    }
  }
  if (pos == -1) {
    swp(str[0], 0, 1);
    printf("%s\n", str[0]);
  } else {
    int now = 0;
    while (str[0][now] == str[pos][now]) {
      now++;
    }
    for (int i = 0; i < n; i++) {
      if (i == now) {
        continue;
      }
      swp(str[0], i, now);
      if (check(str[0], 0)) {
        printf("%s\n", str[0]);
        return 0;
      }
      swp(str[0], i, now);
      swp(str[pos], i, now);
      if (check(str[pos], pos)) {
        printf("%s\n", str[pos]);
        return 0;
      }
      swp(str[pos], i, now);
    }
    puts("-1");
  }
  return 0;
}
