#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const long double eps = 1e-8;
const int mod = 998244353;
const int maxn = 2e5 + 100;
const int N = 1e5 + 100;
const int M = 1e5 + 10;
const long long mm = (1LL << 32);
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= c == '-';
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  x = f ? -x : x;
}
template <class T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  T y = 1;
  int len = 1;
  for (; y <= x / 10; y *= 10) ++len;
  for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}
long long qpow(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ans;
}
int n, k, du[2000];
vector<int> g[2000];
vector<string> a[2000];
vector<string> s;
map<int, int> mp;
int vis[30][30];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    string t;
    for (int j = 1; j <= k; ++j) {
      cin >> t;
      a[x].push_back(t);
    }
  }
  for (int i = 0; i <= n; ++i) {
    int sz = a[i].size();
    if (sz > 0) {
      for (int j = 0; j < k; ++j) {
        s.push_back(a[i][j]);
      }
    }
  }
  int tag = 0;
  for (string tt : s)
    for (char c : tt) mp[c - 'a'] = 1;
  for (int i = 0; i < 26; ++i)
    if (mp[i]) tag++;
  n = s.size();
  for (int i = 1; i < n; ++i) {
    int len1 = s[i - 1].size(), len2 = s[i].size(), flag = 0;
    int mi = min(len1, len2);
    for (int j = 0; j < mi; ++j) {
      if (s[i - 1][j] == s[i][j]) continue;
      flag = 1;
      int u = s[i - 1][j] - 'a', v = s[i][j] - 'a';
      if (!vis[u][v]) g[u].push_back(v), du[v]++;
      vis[u][v] = 1;
      break;
    }
    if (flag == 0 && len1 > len2) {
      cout << "IMPOSSIBLE";
      return 0;
    }
  }
  queue<int> q;
  for (int i = 0; i < 26; ++i) {
    if (mp[i] && !du[i]) q.push(i);
  }
  string ans = "";
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    ans += u + 'a';
    for (int v : g[u]) {
      du[v]--;
      if (du[v] == 0) q.push(v);
    }
  }
  if ((int)ans.size() == tag)
    cout << ans;
  else
    cout << "IMPOSSIBLE";
  return 0;
}
