#include <bits/stdc++.h>
using namespace std;
int n, m, ans, tot, tem, id[41];
map<string, int> vis;
string y;
long long f[41], cur;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int x; i <= n; ++i) {
      cin >> x;
      if (x == 1) break;
      cin >> y;
      if (!vis.count(y)) vis[y] = tot++;
      cur |= 1ll << vis[y];
    }
    for (int j = 0; j < tot; ++j)
      if (cur >> j & 1) f[j] |= cur;
    cur = 0;
  }
  for (int i = 0; i < m; ++i) id[i] = i;
  for (int k = 1; k < 1e4; ++k) {
    random_shuffle(id, id + m);
    tem = cur = 0;
    for (int i = 0; i < m && cur != (1ll << m) - 1; ++i)
      if (!(cur >> id[i] & 1)) cur |= f[id[i]], tem++;
    ans = max(ans, tem);
  }
  cout << ans << endl;
  return 0;
}
