#include <bits/stdc++.h>
using namespace std;
long long magic_const = 3e18;
const int MAX_M = 40;
int n, m;
long long M_DEF;
vector<long long> is_connected;
void init() {
  M_DEF = (1ll << m) - 1;
  is_connected.resize(m, M_DEF);
}
void set_connected(long long x) {
  for (int i = 0; i < m; i++) {
    if (x & (1ll << i)) {
      is_connected[i] &= ~x;
    }
  }
}
vector<int> find_best_clique(vector<int> graph) {
  int m_border = 1 << graph.size();
  vector<int> num(m_border, m_border - 1);
  vector<int> clique_size(m_border, -1);
  clique_size[0] = 0;
  for (int i = 0; i < m_border - 1; i++) {
    if (clique_size[i] == -1) continue;
    for (int j = 0; j < graph.size(); j++) {
      if (i & (1 << j)) continue;
      if (!(num[i] & (1 << j))) continue;
      int now_c = i | (1 << j);
      int now_num = num[i] & graph[j];
      if ((now_num & now_c) == now_c) {
        clique_size[now_c] = clique_size[i] + 1;
        num[now_c] = now_num;
      }
    }
  }
  return clique_size;
}
void solve() {
  cin >> n >> m;
  init();
  map<string, int> mt;
  int max_num = 0;
  long long x = 0;
  for (int i = 0; i < n; i++) {
    int tmp1;
    cin >> tmp1;
    if (tmp1 == 1) {
      set_connected(x);
      x = 0;
    } else {
      string s;
      cin >> s;
      if (mt.find(s) == mt.end()) {
        mt[s] = max_num++;
      }
      x |= (1ll << mt[s]);
    }
  }
  set_connected(x);
  for (int i = 0; i < m; i++) {
    is_connected[i] |= (1ll << i);
  }
  int border = (m - 1) / 2;
  int first_size = border + 1;
  int second_size = m - first_size;
  int sizes[] = {first_size, second_size};
  int begin[] = {0, first_size};
  vector<int> m_t[2][2];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      m_t[i][j].resize(sizes[i]);
      for (int xt = 0; xt < m_t[i][j].size(); xt++) {
        m_t[i][j][xt] = (int)(is_connected[xt + begin[i]] >> begin[j]);
      }
    }
  }
  auto first_clique = find_best_clique(m_t[0][0]);
  auto second_clique = find_best_clique(m_t[1][1]);
  for (int i = 0; i < second_clique.size() - 1; i++) {
    for (int j = 0; j < second_size; j++) {
      if (i & (1 << j)) continue;
      int new_i = i | (1 << j);
      second_clique[new_i] = max(second_clique[new_i], second_clique[i]);
    }
  }
  int best_answer = 0;
  for (int i = 0; i < first_clique.size(); i++) {
    if (first_clique[i] == -1) continue;
    int best_t = (1 << second_size) - 1;
    for (int j = 0; j < first_size; j++) {
      if (i & (1 << j)) best_t &= m_t[0][1][j];
    }
    best_answer = max(best_answer, first_clique[i] + second_clique[best_t]);
  }
  cout << best_answer << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand(555);
  solve();
}
