#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, tot, id[47], ans;
long long f[47], cur;
map<string, int> mp;
string s;
int main() {
  for (cin >> n >> m, i = 1; i <= n; ++i) {
    for (cur = 0; i <= n; ++i) {
      cin >> j;
      if (j == 1) break;
      cin >> s;
      if (!mp.count(s)) mp[s] = tot++;
      cur |= 1LL << mp[s];
    }
    for (j = 0; j < m; ++j)
      if (cur >> j & 1) f[j] |= cur;
  }
  for (i = 0; i < m; ++i) id[i] = i;
  for (j = 0; j < 1e4; ++j) {
    for (random_shuffle(id, id + m), tot = cur = i = 0;
         i < m && cur != (1LL << m) - 1; ++i)
      if (!(cur >> id[i] & 1)) cur |= f[id[i]], tot++;
    ans = max(ans, tot);
  }
  printf("%d\n", ans);
}
