#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000000000000000000;
long long mod = 1000000000;
long double pi = 3.141592653589793238;
void pls() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const long long N = 1e3 + 2;
vector<string> temp[N];
vector<long long> g[28], G[28];
long long connected;
vector<long long> deg(N, 0);
unordered_map<char, long long> conv;
vector<string> arr;
unordered_map<long long, char> rmp;
void dfs(int ix, vector<long long> &visi) {
  visi[ix] = 1;
  connected++;
  for (auto x : G[ix]) {
    if (!visi[x]) dfs(x, visi);
  }
}
void solve() {
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    long long p;
    cin >> p;
    for (int j = 0; j < k; j++) {
      string s;
      cin >> s;
      temp[p].push_back(s);
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < temp[i].size(); j++) arr.push_back(temp[i][j]);
  }
  long long cnt = 1;
  for (int i = 0; i < arr.size(); i++) {
    for (auto x : arr[i]) {
      if (conv.find(x) == conv.end()) conv[x] = cnt++;
    }
    if (i) {
      bool ok = false;
      int j = 0;
      for (; j < arr[i].size() && j < arr[i - 1].size(); j++) {
        if (arr[i - 1][j] != arr[i][j]) {
          long long u = conv[arr[i - 1][j]];
          long long v = conv[arr[i][j]];
          g[u].push_back(v);
          G[u].push_back(v);
          G[v].push_back(u);
          ok = true;
          deg[v]++;
          break;
        }
      }
      if (!ok && j < arr[i - 1].size()) {
        cout << "IMPOSSIBLE";
        return;
      }
    }
  }
  string res = "";
  for (auto x : conv) rmp[x.second] = x.first;
  queue<long long> q;
  for (int i = 1; i < cnt; i++) {
    if (deg[i] == 0) q.push(i);
  }
  while (!q.empty()) {
    long long ix = q.front();
    q.pop();
    res += rmp[ix];
    for (auto x : g[ix]) {
      deg[x]--;
      if (deg[x] == 0) q.push(x);
    }
  }
  if (res.size() == conv.size())
    cout << res << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
int main() {
  pls();
  solve();
  return 0;
}
