#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int M = 40;
long long a[M], cur;
int n, m, t, tot, ans, b[M];
map<string, int> nm;
int main() {
  time_point<steady_clock> start = steady_clock::now();
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  string s;
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    if (i < n) cin >> t;
    if (i == n || t == 1) {
      for (int i = 0; i < m; i++) a[i] |= ((1LL << i) & cur) ? cur : 0;
      cur = 0;
    } else {
      cin >> s;
      if (nm.find(s) == nm.end()) nm[s] = tot++;
      cur |= 1LL << nm[s];
    }
  }
  for (int i = 0; i < m; i++) b[i] = i;
  for (int k = 0; k < 500; k++) {
    random_shuffle(b, b + m);
    cur = 0;
    t = 0;
    for (int i = 0; i < m && cur != (1LL << m) - 1; i++) {
      if (!((1LL << b[i]) & cur)) {
        if (++t > ans) ans = t;
        cur |= a[b[i]];
      }
    }
  }
  cout << ans << endl;
  cerr << endl
       << "------------------------------" << endl
       << "Time: "
       << duration<double, milli>(steady_clock::now() - start).count() << " ms."
       << endl;
  return 0;
}
