#include <bits/stdc++.h>
using namespace std;
inline int ReadInt() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void WriteInt(int x) {
  char CH[20];
  int Num = 0;
  if (!x) {
    putchar('0');
    puts("");
    return;
  }
  while (x > 0) CH[++Num] = x % 10, x /= 10;
  while (Num) putchar(CH[Num--] + 48);
  puts("");
}
int aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, mm, nn, oo, pp, qq, rr, ss, tt,
    uu, vv, ww, xx, yy, zz;
int tc, ty;
long long notFriend[44];
int n, m, ans, dp[1 << 21];
map<string, int> mp;
void backtrack1(int i, long long taken) {
  if (i == m >> 1) return (void)(dp[taken] = __builtin_popcountll(taken));
  backtrack1(i + 1, taken);
  if (!(notFriend[i] & taken)) backtrack1(i + 1, taken | (1LL << i));
}
void backtrack2(int i, long long taken) {
  if (i == m) {
    long long mask = 0;
    for (int j = 0; j < m; j++)
      if (taken & 1LL << j) mask |= notFriend[j];
    mask = ~mask;
    mask &= (1LL << (m >> 1)) - 1;
    ans = max(ans, dp[mask] + __builtin_popcountll(taken));
    return;
  }
  backtrack2(i + 1, taken);
  if (!(notFriend[i] & taken)) backtrack2(i + 1, taken | (1LL << i));
}
void sos() {
  for (int i = 0; i < (m >> 1); i++)
    for (int mask = 0; mask < (1 << (m >> 1)); mask++)
      if (mask & 1 << i) dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]);
}
int main() {
  scanf("%i%i", &n, &m);
  int ty;
  vector<int> v;
  while (scanf("%i", &ty) != EOF) {
    if (ty & 2) {
      string s;
      cin >> s;
      int id = mp[s] ? mp[s] : mp[s] = mp.size();
      v.push_back(id - 1);
      continue;
    }
  rep:
    if (v.empty()) continue;
    for (int i = 0; i < v.size(); i++)
      for (int j = i + 1; j < v.size(); j++) {
        notFriend[v[j]] |= (1LL << v[i]);
        notFriend[v[i]] |= (1LL << v[j]);
      }
    v.clear();
  }
  if (n) {
    n = 0;
    goto rep;
  }
  backtrack1(0, 0);
  sos();
  backtrack2(m >> 1, 0);
  cout << ans << endl;
}
