#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int M = 41, Z = 1 << 20;
map<string, int> mp;
long long w[M], used[M], c[Z];
int sz[Z], dp[Z];
bool t[Z];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  if (m == 1) {
    cout << 1;
    return 0;
  }
  vector<string> v;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    string s;
    if (t == 2) {
      cin >> s;
      if (!mp.count(s)) {
        int x = mp.size();
        mp[s] = x;
      }
    }
    v.push_back(s);
  }
  v.push_back("");
  for (int x = 0; x < m; x++) {
    for (int y = 0; y < m; y++) {
      w[x] |= 1ll << y;
    }
  }
  for (int i = 0; i < v.size(); i++) {
    if (v[i].empty()) {
      for (int x = 0; x < m; x++) {
        for (int y = 0; y < m; y++) {
          if (used[x] && used[y]) w[x] &= ~(1ll << y);
        }
      }
      fill(used, used + m, 0);
    } else {
      used[mp[v[i]]] = 1;
    }
  }
  for (int i = 0; i < 20; i++) {
    sz[1 << i] = 1;
  }
  for (int i = 1; i < Z; i++) {
    sz[i] = sz[i & -i] + sz[i ^ (i & -i)];
  }
  int h = m / 2;
  for (int i = 0; i < h; i++) {
    t[1 << i] = 1;
    c[1 << i] = w[i];
  }
  int ans = 0;
  for (int i = 1; i < (1 << h); i++) {
    if (t[i]) {
      ans = max(ans, sz[i]);
      for (int j = 0; j < h; j++) {
        if ((c[i] >> j) & 1) {
          int x = i | (1 << j);
          t[x] = 1;
          c[x] = c[i] & w[j];
        }
      }
    }
  }
  vector<pair<int, long long>> q;
  for (int i = 1; i < (1 << h); i++) {
    if (t[i]) {
      q.push_back({sz[i], c[i] >> h});
    }
  }
  for (int i = h; i < m; i++) w[i - h] = w[i] >> h;
  h = m - h;
  fill(t, t + Z, 0);
  fill(c, c + Z, 0);
  for (int i = 0; i < h; i++) {
    t[1 << i] = 1;
    c[1 << i] = w[i];
  }
  for (int i = 1; i < (1 << h); i++) {
    if (t[i]) {
      ans = max(ans, sz[i]);
      for (int j = 0; j < h; j++) {
        if ((c[i] >> j) & 1) {
          int x = i | (1 << j);
          t[x] = 1;
          c[x] = c[i] & w[j];
        }
      }
    }
  }
  for (int i = 1; i < (1 << h); i++) {
    if (t[i]) {
      dp[i] = sz[i];
    } else {
      for (int j = 0; j < h; j++) {
        if (((i >> j) & 1)) {
          dp[i] = max(dp[i], dp[i ^ (1 << j)]);
        }
      }
    }
  }
  for (auto p : q) {
    ans = max(ans, dp[p.second] + p.first);
  }
  cout << ans;
  return 0;
}
