#include <bits/stdc++.h>
using namespace std;
long long int f[2000100];
long long int t[50];
void upd(long long int mask, long long int x) {
  if (x < 0) return;
  upd(mask ^ (1LL << x), x - 1);
  upd(mask, x - 1);
  for (int i = 0; i < (1LL << x); i++)
    f[mask ^ i] = max(f[mask ^ i], f[mask ^ i ^ (1LL << x)]);
}
map<string, long long int> ma;
int main() {
  long long int n, m, type, cnt = 0;
  long long int mask = 0;
  string s;
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) {
    cin >> type;
    if (type == 1) {
      for (long long int j = 0; j < m; j++) {
        if ((1LL << j) & mask) t[j] |= mask;
      }
      mask = 0;
    } else {
      cin >> s;
      if (ma.find(s) == ma.end()) ma[s] = cnt++;
      long long int j = ma[s];
      mask |= (1LL << j);
    }
  }
  for (long long int j = 0; j < m; j++) {
    if ((1LL << j) & mask) t[j] |= mask;
  }
  mask = 0;
  long long int half = m / 2;
  for (long long int i = 0; i < (1 << half); i++) {
    bool br = false;
    for (long long int j = 0; j < half; j++) {
      if ((i & (1LL << j))) {
        if ((i & t[j]) ^ (1LL << j)) {
          br = true;
          break;
        }
      }
    }
    if (!br) {
      f[i] = __builtin_popcountll(i);
    }
  }
  upd((1 << half) - 1, half - 1);
  long long int ans = 0;
  for (long long int temp = 0; temp < (1LL << (m - half)); temp++) {
    long long int MASK = 0, i = (1LL * temp) << half;
    bool br = false;
    for (long long int j = half; j < m; j++) {
      if ((i & (1LL << j))) {
        if ((i & t[j]) ^ (1LL << j)) {
          br = true;
          break;
        }
        MASK |= t[j];
      }
    }
    if (!br) {
      ans = max(ans, f[(MASK & ((1LL << half) - 1)) ^ ((1LL << half) - 1)] +
                         __builtin_popcountll(i));
    }
  }
  cout << ans;
}
