#include <bits/stdc++.h>
using namespace std;
const int maxn = 7e5 + 5;
const int mod = 1e9 + 7;
string s;
vector<string> v[maxn];
int n, k, d;
int in[maxn], vis[maxn];
vector<int> G[maxn];
void cmp(string x, string y) {
  int lx = x.length(), ly = y.length(), f = 0;
  for (int i = 0; i < min(lx, ly); i++) {
    ;
    if (x[i] == y[i]) continue;
    G[x[i]].push_back(y[i]);
    in[y[i]]++;
    f = 1;
    break;
  }
  for (int i = 0; i < lx; i++) vis[x[i]] = 1;
  for (int i = 0; i < ly; i++) vis[y[i]] = 1;
  if (lx > ly) {
    if (f == 0) {
      cout << "IMPOSSIBLE\n";
      exit(0);
    }
  }
}
queue<int> q;
char ans[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> d;
    for (int j = 1; j <= k; j++) {
      cin >> s;
      v[d].push_back(s);
    }
  }
  string now = "";
  for (int i = 0; i < n; i++) {
    for (string j : v[i]) {
      if (now.size() == 0) {
        now = j;
        int sz = j.size();
        for (int l = 0; l < sz; l++) vis[j[l]] = 1;
      } else {
        cmp(now, j);
        now = j;
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= 1000; i++) {
    if (in[i] == 0 && vis[i]) {
      q.push(i);
    }
  }
  while (!q.empty()) {
    int f = q.front();
    q.pop();
    ans[++cnt] = f;
    for (int v : G[f]) {
      in[v]--;
      if (in[v] == 0) q.push(v);
    }
  }
  for (int i = 1; i <= 1000; i++) {
    if (in[i]) {
      cout << "IMPOSSIBLE\n";
      return 0;
    }
  }
  for (int i = 1; i <= cnt; i++) cout << ans[i];
  cout << endl;
  return 0;
}
