#include <bits/stdc++.h>
using namespace std;
const int N = 1048576 + 7;
const int M = 40 + 7;
const int K = 100000 + 7;
int n, m, ans;
int cnt, tot, ty[K];
long long con[M], mst[M], bi[M];
string s;
map<string, int> mp;
int lim1, lim2;
void read() {
  cin >> m >> n;
  bi[1] = 1;
  for (int i = 2; i <= n; i++) bi[i] = bi[i - 1] << 1LL;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &ty[i]);
    if (ty[i] == 1) continue;
    cin >> s;
    if (!mp[s]) mp[s] = ++tot;
    int k = mp[s];
    if (ty[i - 1] == 2)
      con[cnt] |= bi[k];
    else {
      cnt++;
      con[cnt] = bi[k];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= cnt; j++)
      if (con[j] & bi[i]) mst[i] |= con[j];
    mst[i] ^= bi[i];
  }
}
int val[N], num[N], cant[N];
bool on[N];
void pre() {
  lim1 = n / 2;
  lim2 = n - lim1;
  for (int sta = 0; sta < (1 << lim1); sta++) {
    int cnt = 0;
    bool flag = 1;
    for (int i = 1; i <= lim1; i++)
      if (sta & bi[i]) {
        cnt++;
        if (sta & mst[i]) {
          flag = 1;
          break;
        }
      }
    if (!flag) continue;
    val[sta] = cnt;
  }
  for (int sta = 0; sta < (1 << lim1); sta++) {
    for (int i = 1; i <= lim1; i++)
      if (sta & bi[i]) val[sta] = max(val[sta], val[sta ^ bi[i]]);
  }
  for (int sta = 0; sta < (1 << lim2); sta++) {
    bool flag = 1;
    for (int i = lim1 + 1; i <= n; i++)
      if (sta & (bi[i] >> lim1)) {
        num[sta]++;
        cant[sta] |= mst[i];
        cant[sta] &= (1 << lim1) - 1;
        if (sta & (mst[i] >> lim1)) {
          flag = 0;
          break;
        }
      }
    if (!flag) continue;
    on[sta] = 1;
  }
}
int all;
void work() {
  all = (1 << lim1) - 1;
  for (int sta = 0; sta < (1 << lim2); sta++) {
    if (!on[sta]) continue;
    ans = max(ans, val[all ^ cant[sta]] + num[sta]);
  }
}
int main() {
  read();
  pre();
  work();
  printf("%d\n", ans);
  return 0;
}
