#include <bits/stdc++.h>
using namespace std;
string ss[2525];
int T, n;
int check(string s) {
  int t;
  int tag = 0;
  char cc[30];
  memset(cc, 0, sizeof(cc));
  for (int i = 0; i < n; ++i) {
    cc[s[i] - 'a']++;
  }
  for (int i = 0; i < 26; ++i) {
    if (cc[i] >= 2) tag = 1;
  }
  for (int tt = 0; tt < T; ++tt) {
    t = 0;
    for (int i = 0; i < n; ++i) {
      if (ss[tt][i] != s[i]) t++;
      if (t > 2) {
        return 0;
      }
    }
    if ((t == 0 && tag == 1) || t == 2)
      ;
    else
      return 0;
  }
  return 1;
}
int main() {
  cin >> T >> n;
  cin >> ss[0];
  char ch[30];
  int pos[10];
  int flag = 0;
  int pp[5], k, t;
  int cc[30];
  memset(ch, 0, sizeof(ch));
  for (int i = 0; i < n; ++i) {
    ch[ss[0][i] - 'a']++;
  }
  for (int tt = 1; tt < T; ++tt) {
    cin >> ss[tt];
    t = 0;
    memset(cc, 0, sizeof(cc));
    for (int i = 0; i < n; ++i) {
      cc[ss[tt][i] - 'a']++;
      if (ss[tt][i] != ss[0][i]) pos[t++] = i;
      if (t > 4) {
        printf("-1\n");
        return 0;
      }
    }
    for (int i = 0; i < 26; ++i) {
      if (ch[i] != cc[i]) {
        printf("-1\n");
        return 0;
      }
    }
    if (t == 1) {
      printf("-1\n");
      return 0;
    } else if (t == 2) {
      if (cc[(int)ss[tt][pos[0]] - 'a'] > 1 || cc[(int)ss[tt][pos[1]] - 'a']) {
        if (flag < 2) {
          flag = 2;
          k = tt;
          pp[0] = pos[0];
          pp[1] = pos[1];
        }
      }
    } else if (t == 3) {
      if ((ss[0][pos[0]] == ss[tt][pos[1]] && ss[0][pos[1]] == ss[tt][pos[2]] &&
           ss[0][pos[2]] == ss[tt][pos[0]]) ||
          (ss[0][pos[0]] == ss[tt][pos[2]] && ss[0][pos[1]] == ss[tt][pos[0]] &&
           ss[0][pos[2]] == ss[tt][pos[1]])) {
        if (flag < 3) {
          pp[0] = pos[0];
          pp[1] = pos[1];
          pp[2] = pos[2];
          flag = 3;
          k = tt;
        }
      } else {
        printf("-1\n");
        return 0;
      }
    } else if (t == 4) {
      if ((ss[0][pos[0]] == ss[tt][pos[1]] && ss[0][pos[1]] == ss[tt][pos[0]] &&
           ss[0][pos[2]] == ss[tt][pos[3]] &&
           ss[0][pos[3]] == ss[tt][pos[2]]) ||
          (ss[0][pos[0]] == ss[tt][pos[2]] && ss[0][pos[1]] == ss[tt][pos[3]] &&
           ss[0][pos[2]] == ss[tt][pos[0]] &&
           ss[0][pos[3]] == ss[tt][pos[1]]) ||
          (ss[0][pos[0]] == ss[tt][pos[3]] && ss[0][pos[1]] == ss[tt][pos[2]] &&
           ss[0][pos[2]] == ss[tt][pos[1]] &&
           ss[0][pos[3]] == ss[tt][pos[0]])) {
        if (flag < 4) {
          flag = 4;
          pp[0] = pos[0];
          pp[1] = pos[1];
          pp[2] = pos[2];
          pp[3] = pos[3];
        }
      } else {
        printf("-1\n");
        return 0;
      }
    }
  }
  string ans = "";
  if (check(ss[0])) ans = ss[0];
  char c;
  string st;
  st = ss[0];
  c = st[0];
  st[0] = st[1];
  st[1] = c;
  if (check(st)) ans = st;
  if (flag == 3) {
    char c;
    string st;
    st = ss[0];
    c = st[pp[0]];
    st[pp[0]] = st[pp[1]];
    st[pp[1]] = c;
    if (check(st)) ans = st;
    st = ss[0];
    c = st[pp[0]];
    st[pp[0]] = st[pp[2]];
    st[pp[2]] = c;
    if (check(st)) ans = st;
    st = ss[0];
    c = st[pp[2]];
    st[pp[2]] = st[pp[1]];
    st[pp[1]] = c;
    if (check(st)) ans = st;
  }
  if (flag == 4) {
    char c;
    string st;
    st = ss[0];
    c = st[pp[0]];
    st[pp[0]] = st[pp[1]];
    st[pp[1]] = c;
    if (check(st)) ans = st;
    st = ss[0];
    c = st[pp[0]];
    st[pp[0]] = st[pp[2]];
    st[pp[2]] = c;
    if (check(st)) ans = st;
    st = ss[0];
    c = st[pp[0]];
    st[pp[0]] = st[pp[3]];
    st[pp[3]] = c;
    if (check(st)) ans = st;
    st = ss[0];
    c = st[pp[1]];
    st[pp[1]] = st[pp[2]];
    st[pp[2]] = c;
    if (check(st)) ans = st;
    st = ss[0];
    c = st[pp[1]];
    st[pp[1]] = st[pp[3]];
    st[pp[3]] = c;
    if (check(st)) ans = st;
    st = ss[0];
    c = st[pp[2]];
    st[pp[2]] = st[pp[3]];
    st[pp[3]] = c;
    if (check(st)) ans = st;
  }
  if (flag == 2) {
    if (check(ss[0])) ans = ss[0];
    for (int i = 0; i < n; ++i) {
      if (ans != "") break;
      if (pp[0] == i) continue;
      st = ss[0];
      c = st[pp[0]];
      st[pp[0]] = st[i];
      st[i] = c;
      if (check(st)) ans = st;
    }
    for (int i = 0; i < n; ++i) {
      if (ans != "") break;
      if (pp[1] == i) continue;
      st = ss[0];
      c = st[pp[1]];
      st[pp[1]] = st[i];
      st[i] = c;
      if (check(st)) ans = st;
    }
    for (int i = 0; i < n; ++i) {
      if (ans != "") break;
      if (pp[0] == i) continue;
      st = ss[k];
      c = st[pp[0]];
      st[pp[0]] = st[i];
      st[i] = c;
      if (check(st)) ans = st;
    }
    for (int i = 0; i < n; ++i) {
      if (ans != "") break;
      if (pp[1] == i) continue;
      st = ss[k];
      c = st[pp[1]];
      st[pp[1]] = st[i];
      st[i] = c;
      if (check(st)) ans = st;
    }
  }
  if (ans == "") {
    cout << -1 << endl;
  } else
    cout << ans << endl;
  return 0;
}
