#include <bits/stdc++.h>
using namespace std;
string s;
int n, m;
long long cur, v1[100], barosaneala[100], b, q, nr, maxim;
map<string, int> nande;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    while (cin >> b && b == 2 && i < n) {
      cin >> s;
      if (!nande[s]) {
        q++;
        nande[s] = q;
      }
      cur |= ((long long)1 << (nande[s] - 1));
      i++;
    }
    for (int j = 1; j <= m; j++) {
      if (((long long)1 << (j - 1)) & cur) {
        barosaneala[j - 1] |= cur;
      }
    }
    cur = 0;
  }
  for (int i = 0; i < m; i++) {
    v1[i] = i;
  }
  for (int i = 0; i < 40 * 40; i++) {
    random_shuffle(v1, v1 + m);
    nr = 0;
    cur = 0;
    for (int j = 0; j < m; j++) {
      if ((cur | ((long long)1 << v1[j])) > cur) {
        cur |= barosaneala[v1[j]];
        nr++;
      }
    }
    if (nr > maxim) {
      maxim = nr;
    }
  }
  cout << maxim;
  return 0;
}
