#include <bits/stdc++.h>
using namespace std;
void readi(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readll(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
void writes(string s) { puts(s.c_str()); }
void writeln() { writes(""); }
void writei(int x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
void writell(long long x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
long long qp(long long x, long long y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  long long z = qp(x, y / 2);
  z = z * z % 1000000007;
  if (y & 1) z = z * x % 1000000007;
  return z;
}
string s[5005];
int n, m, i, j, k, cnt[5005];
bool p[5005][5005], eq[5005];
set<char> ss;
map<char, int> mm, m2;
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (i = 0; i < m; i++) mm[s[1][i]]++;
  for (i = 2; i <= n; i++) {
    m2.clear();
    for (j = 0; j < m; j++) m2[s[i][j]]++;
    if (mm != m2) {
      cout << -1;
      return 0;
    }
    for (j = 0; j < m; j++) {
      if (s[1][j] != s[i][j]) {
        p[i][j] = 1;
        cnt[i]++;
      }
    }
    ss.clear();
    for (j = 0; j < m; j++) {
      if (ss.count(s[i][j])) {
        eq[i] = 1;
        break;
      }
      ss.insert(s[i][j]);
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < m; j++) {
      if (i == j) continue;
      bool ok = 1;
      for (k = 2; k <= n; k++) {
        int t = cnt[k];
        if (s[k][i] == s[1][i]) t++;
        if (s[k][j] == s[1][j]) t++;
        if (s[k][j] == s[1][i]) t--;
        if (s[k][i] == s[1][j]) t--;
        if (t == 0 && eq[k]) continue;
        if (t == 2) continue;
        ok = 0;
        break;
      }
      if (ok) {
        swap(s[1][i], s[1][j]);
        cout << s[1];
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
