#include <bits/stdc++.h>
using namespace std;
int n, m;
map<string, int> id;
bitset<151010> bit[50];
int ms[3][50];
int unf[50][50];
void pre(int i1, int i2, int j1, int j2, int p) {
  for (int i = i1, b1 = 0; i < i2; i++, b1++) {
    for (int j = j1, b2 = 0; j < j2; j++, b2++) {
      if (i == j) continue;
      if ((bit[i] & bit[j]).count()) {
        unf[i][j] = 1;
        ms[p][i] |= (1 << b2);
      }
    }
  }
}
int ta = (1 << 21) - 1;
int dp[1 << 21];
void get(int id, int msk1 = 0, int msk2 = 0, int r = 0) {
  if (id == m / 2) {
    dp[msk2 ^ ta] = max(dp[msk2 ^ ta], r);
    return;
  }
  get(id + 1, msk1, msk2, r);
  if ((msk1 & ms[0][id]) == 0) {
    get(id + 1, msk1 | (1 << id), msk2 | ms[1][id], r + 1);
  }
}
int dp1[1 << 21][25];
int solve(int ms, int i) {
  if (i == 21) return dp[ms];
  int &ret = dp1[ms][i];
  if (ret != -1) return ret;
  ret = solve(ms, i + 1);
  if (!(ms & (1 << i))) {
    ret = max(ret, solve(ms | (1 << i), i + 1));
  }
  return ret;
}
int ans = 0, mi;
void getans(int id, int msk1 = 0, int msk2 = 0, int r = 0) {
  if (id == m) {
    ans = max(ans, r + solve(msk1, 0));
    return;
  }
  getans(id + 1, msk1, msk2, r);
  if ((msk1 & ms[0][id]) == 0) {
    getans(id + 1, msk1 | (1 << (id - mi)), msk2 | ms[1][id], r + 1);
  }
}
int main() {
  cin >> n >> m;
  mi = m / 2;
  int cnt = 0, c = 0;
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      c = 0;
    } else {
      string s;
      cin >> s;
      if (!c) {
        c = i;
      }
      if (!id.count(s)) id[s] = cnt++;
      bit[id[s]][c] = 1;
    }
  }
  memset(dp1, -1, sizeof dp1);
  pre(0, mi, 0, mi, 0);
  pre(0, mi, mi, m, 1);
  pre(mi, m, 0, mi, 1);
  pre(mi, m, mi, m, 0);
  get(0);
  getans(m / 2);
  cout << ans;
}
