#include <bits/stdc++.h>
using namespace std;
long long adj[40][40];
long long masks[40];
int m;
int n;
int dp[(1 << 20)];
int up;
int solve1(int mask) {
  if (mask == 0) return 0;
  if (dp[mask] != -1) return dp[mask];
  int val;
  for (int j = int(0); j <= int(m / 2 - 1); j++) {
    if (mask & (1 << j)) {
      val = j;
      break;
    }
  }
  int u = mask - (1 << val);
  dp[mask] = solve1(u);
  int nu = mask;
  nu &= masks[val];
  dp[mask] = (dp[mask] > 1 + solve1(nu) ? dp[mask] : 1 + solve1(nu));
  return dp[mask];
}
int solve2(long long mask) {
  if (mask <= up) return dp[mask];
  long long val;
  for (int i = int(m / 2); i <= int(m - 1); i++) {
    if (mask & (1LL << i)) {
      val = i;
      break;
    }
  }
  long long u = mask - (1LL << val);
  long long ans = solve2(u);
  ans = (ans > 1 + solve2(mask & masks[val]) ? ans
                                             : 1 + solve2(mask & masks[val]));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  up = (1 << (m / 2)) - 1;
  for (int i = int(0); i <= int(m - 1); i++) {
    for (int j = int(0); j <= int(m - 1); j++) adj[i][j] = 1;
  }
  unordered_set<int> s;
  map<string, int> label;
  int ind = -1;
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  for (int i = int(1); i <= int(n); i++) {
    int x;
    cin >> x;
    if (i == 1)
      continue;
    else if (x == 1) {
      if (s.empty()) continue;
      for (auto it : s) {
        for (auto it2 : s) adj[it][it2] = 0;
      }
      s.clear();
    } else {
      string u;
      cin >> u;
      if (!label.empty() && label.find(u) != label.end())
        s.insert(label[u]);
      else {
        ind++;
        label[u] = ind;
        s.insert(ind);
      }
    }
  }
  if (!s.empty()) {
    for (auto it : s) {
      for (auto it2 : s) adj[it][it2] = 0;
    }
    s.clear();
  }
  for (int i = int(0); i <= int(m - 1); i++) {
    for (int j = int(0); j <= int(m - 1); j++)
      masks[i] += (adj[i][j]) * ((1LL << j));
  }
  if (m == 1) {
    cout << 1;
    return 0;
  }
  for (int i = int(0); i <= int((1 << (m / 2)) - 1); i++) int p = solve1(i);
  cout << solve2((1LL << m) - 1);
}
