#include <bits/stdc++.h>
using namespace std;
int n, m;
using namespace std;
const int N = 41;
const int M = 25005;
bool w[N][N];
map<string, int> name_to_id;
int current_id;
int get_id(const string& s) {
  if (name_to_id.find(s) == name_to_id.end()) {
    name_to_id[s] = current_id++;
  }
  return name_to_id[s];
}
int mx;
int dp[N];
int _stack[N][N];
void dfs(int n, int num, int step) {
  if (num == 0) {
    if (step > mx) {
      mx = step;
      return;
    }
  }
  for (int i = 0; i < num; i++) {
    int k = _stack[step][i];
    if (step + n - k <= mx) return;
    if (step + dp[k] <= mx) return;
    int cnt = 0;
    for (int j = i + 1; j < num; j++) {
      if (w[k][_stack[step][j]]) {
        _stack[step + 1][cnt++] = _stack[step][j];
      }
    }
    dfs(N, cnt, step + 1);
  }
}
bool my_vis[44];
void add_edge(const set<int>& v) {
  for (auto i : v)
    for (auto j : v) {
      w[i][j] = w[j][i] = 0;
    }
}
void solve() {
  current_id = 0;
  memset(my_vis, 0, sizeof my_vis);
  memset(w, true, sizeof(w));
  set<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x == 1) {
      add_edge(v);
      v.clear();
      continue;
    }
    if (x == 2) {
      string s;
      cin >> s;
      v.insert(get_id(s));
    }
  }
  add_edge(v);
  mx = 0;
  for (int i = m - 1; i >= 0; i--) {
    int cnt = 0;
    for (int j = i + 1; j < m; j++) {
      if (w[i][j]) _stack[1][cnt++] = j;
    }
    dfs(N, cnt, 1);
    dp[i] = mx;
  }
  cout << dp[0] << endl;
}
int main() {
  while (cin >> n >> m) solve();
}
