#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin>>n>>m;
  vector<vector<int>>G(n,vector<int>());
  for(int i=0;i<m;++i){
    int x,y;
    cin>>x>>y;
    x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  vector<int>a(n);
  queue<int>q;
  vector<int>rk(n),vis(n),b(n);
  for(int i=0;i<n;++i){
    cin>>a[i];
    a[i]--;
    if(a[i]==0) q.push(i),vis[i]=1;
  }
  int cnt=0;
  int ok=1;
  for(int i=0;i<n;++i){
    if(a[i]==0){
      for(int j:G[i]){
        if(a[j]==0) ok=0;
      }
    }
  }
  while(q.size()){
    auto x=q.front();
    q.pop();
    vis[x]=1;
    rk[x]=cnt++;
    for(int y:G[x]){
      //if(vis[y]&&a[x]==a[y]) ok=0;
      if(vis[y]&&a[x]<=a[y]) ok=0;
      if(b[y]==a[x]) b[y]++;
      if(vis[y]) continue;
      if(b[y]!=a[y]) continue;
      //if(a[y]!=a[x]+1) continue;
      q.push(y),vis[y]=1;
    }
  }
  if(!ok||cnt!=n){
    cout<<"-1\n";
    exit(0);
  }
  vector<int>an(n);
  for(int i=0;i<n;++i) an[rk[i]]=i;
  for(int i=0;i<n;++i) cout<<an[i]+1<<" \n"[i==n-1];
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin>>n>>m;
  vector<vector<int>>G(n,vector<int>());
  for(int i=0;i<m;++i){
    int x,y;
    cin>>x>>y;
    x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  vector<int>a(n);
  queue<int>q;
  vector<int>rk(n),vis(n),b(n);
  for(int i=0;i<n;++i){
    cin>>a[i];
    a[i]--;
    if(a[i]==0) q.push(i),vis[i]=1;
  }
  int cnt=0;
  int ok=1;
  for(int i=0;i<n;++i){
    if(a[i]==0){
      for(int j:G[i]){
        if(a[j]==0) ok=0;
      }
    }
  }
  while(q.size()){
    auto x=q.front();
    q.pop();
    vis[x]=1;
    rk[x]=cnt++;
    for(int y:G[x]){
      //if(vis[y]&&a[x]==a[y]) ok=0;
      if(vis[y]&&a[x]==a[y]) ok=0;
      if(b[y]==a[x]) b[y]++;
      if(vis[y]) continue;
      if(b[y]!=a[y]) continue;
      //if(a[y]!=a[x]+1) continue;
      q.push(y),vis[y]=1;
    }
  }
  if(!ok||cnt!=n){
    cout<<"-1\n";
    exit(0);
  }
  vector<int>an(n);
  for(int i=0;i<n;++i) an[rk[i]]=i;
  for(int i=0;i<n;++i) cout<<an[i]+1<<" \n"[i==n-1];
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin>>n>>m;
  vector<vector<int>>G(n,vector<int>());
  for(int i=0;i<m;++i){
    int x,y;
    cin>>x>>y;
    x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  vector<int>a(n);
  queue<int>q;
  vector<int>rk(n),vis(n);
  for(int i=0;i<n;++i){
    cin>>a[i];
    if(a[i]==1) q.push(i),vis[i]=1;
  }
  int cnt=0;
  int ok=1;
  while(q.size()){
    auto x=q.front();
    q.pop();
    vis[x]=1;
    rk[x]=cnt++;
    for(int y:G[x]){
      if(vis[y]&&a[x]==a[y]) ok=0;
      if(vis[y]) continue;
      if(a[y]!=a[x]+1) continue;
      q.push(y),vis[y]=1;
    }
  }
  if(!ok||cnt!=n){
    cout<<"-1\n";
    exit(0);
  }
  vector<int>an(n);
  for(int i=0;i<n;++i) an[rk[i]]=i;
  for(int i=0;i<n;++i) cout<<an[i]+1<<" \n"[i==n-1];
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin>>n>>m;
  vector<vector<int>>G(n,vector<int>());
  for(int i=0;i<m;++i){
    int x,y;
    cin>>x>>y;
    x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  vector<int>a(n);
  queue<int>q;
  vector<int>rk(n),vis(n);
  for(int i=0;i<n;++i){
    cin>>a[i];
    if(a[i]==1) q.push(i),vis[i]=1;
  }
  int cnt=0;
  int ok=1;
  for(int i=0;i<n;++i){
    if(a[i]==1){
      for(int j:G[i]){
        if(a[j]==1) ok=0;
      }
    }
  }
  while(q.size()){
    auto x=q.front();
    q.pop();
    vis[x]=1;
    rk[x]=cnt++;
    for(int y:G[x]){
      //if(vis[y]&&a[x]==a[y]) ok=0;
      if(vis[y]) continue;
      if(a[y]!=a[x]+1) continue;
      q.push(y),vis[y]=1;
    }
  }
  if(!ok||cnt!=n){
    cout<<"-1\n";
    exit(0);
  }
  vector<int>an(n);
  for(int i=0;i<n;++i) an[rk[i]]=i;
  for(int i=0;i<n;++i) cout<<an[i]+1<<" \n"[i==n-1];
  return 0;
}


/**
 *  Author: Bao Tong
 *  Created: Sun 19/07/2020 at 00:21:05
 **/

#include <bits/stdc++.h>
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                              \
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
            c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << "," << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int N = 2e5 + 6;
int n, m;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  vector<vector<int>> adj(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<int> degree(n + 1);
  vector<pair<int, int>> topic;
  for (int i = 1; i <= n; i++) {
    int tmp;
    cin >> tmp;
    topic.push_back({tmp, i});
  }
  sort(topic.begin(), topic.end());
  bool can = true;
  for (auto top : topic) {
    int val = top.first, index = top.second;
    if (degree[index] != val - 1) {
      can = false;
      break;
    } else {
      for (auto edge : adj[index]) {
        degree[edge]++;
      }
    }
  }
  if (can) {
    for (auto top : topic) {
      cout << top.second << " ";
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

/**
 * A worthwhile goal
 * Make a damn schedule and stick to it
 **/


/**
 *  Author: Bao Tong
 *  Created: Sun 19/07/2020 at 00:21:05
 **/

#include <bits/stdc++.h>
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                              \
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
            c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << "," << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int N = 2e5 + 6;
int n, m;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  vector<vector<int>> adj(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<int> degree(n + 1);
  vector<pair<int, int>> topic;
  for (int i = 1; i <= n; i++) {
    int tmp;
    cin >> tmp;
    topic.push_back({tmp, i});
  }
  sort(topic.begin(), topic.end());
  bool can = true;
  queue<int> qu;
  int last = 0;
  for (auto top : topic) {
    int val = top.first, index = top.second;
    if (val != last) {
      last = val;
      while (!qu.empty()) {
        degree[qu.front()]++;
        qu.pop();
      }
    }
    if (degree[index] != val - 1) {
      can = false;
      break;
    } else {
      for (auto edge : adj[index]) {
        qu.push(edge);
      }
    }
  }
  if (can) {
    for (auto top : topic) {
      cout << top.second << " ";
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

/**
 * A worthwhile goal
 * Make a damn schedule and stick to it
 **/


/**
 *  Author: Bao Tong
 *  Created: Sun 19/07/2020 at 00:21:05
 **/

#include <bits/stdc++.h>
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                              \
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
            c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << "," << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int N = 2e5 + 6;
int n, m;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  vector<vector<int>> adj(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<int> degree(n + 1);
  vector<pair<int, int>> topic;
  for (int i = 1; i <= n; i++) {
    int tmp;
    cin >> tmp;
    topic.push_back({tmp, i});
  }
  sort(topic.begin(), topic.end());
  bool can = true;
  queue<int> qu;
  int last = 0;
  for (auto top : topic) {
    int val = top.first, index = top.second;
    if (val != last) {
      last = val;
      while (!qu.empty()) {
        degree[qu.front()]++;
        qu.pop();
      }
    }
    if (degree[index] < val - 1) {
      can = false;
      break;
    } else {
      for (auto edge : adj[index]) {
        qu.push(edge);
      }
    }
  }
  if (can) {
    for (auto top : topic) {
      cout << top.second << " ";
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

/**
 * A worthwhile goal
 * Make a damn schedule and stick to it
 **/


/**
 *  Author: Bao Tong
 *  Created: Sun 19/07/2020 at 00:21:05
 **/

#include <bits/stdc++.h>
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                              \
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
            c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << "," << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int N = 2e5 + 6;
int n, m;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  vector<vector<int>> adj(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<int> degree(n + 1), d(n + 1);
  vector<pair<int, int>> topic;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    topic.push_back({d[i], i});
  }
  sort(topic.begin(), topic.end());
  bool can = true;
  for (auto top : topic) {
    int val = top.first, index = top.second;
    if (degree[index] != val - 1) {
      can = false;
      break;
    } else {
      for (auto edge : adj[index]) {
        if (degree[edge] == val - 1) {
          degree[edge]++;
        }
      }
    }
  }
  if (can) {
    for (auto top : topic) {
      cout << top.second << " ";
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

/**
 * A worthwhile goal
 * Make a damn schedule and stick to it
 **/


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define oo 1000000000
#define ool 1000000000000000000
using namespace std;
int n, m;
vector<int> g[500100];
int t[500100], used[500100], an[500100];

bool comp(int a, int b){
	return t[a] < t[b];
}

int main(){
	cin >> n >> m;
	for(int i = 0 ; i < m; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i = 1; i <= n; i++){
		cin >> t[i];
		an[i] = i;
	}

	for(int i = 1; i <= n; i++){
		for(int v : g[i]){
			if(t[v] == t[i]){
				cout << -1 << endl;
				return 0;
			}
			used[t[v]] = 1;
		}
		for(int j = 1; j < t[i]; j++){
			if(used[j] == 0){
				cout << -1 << endl;
				return 0;
			}
			else used[j];
		}
	}

	sort(an + 1, an + n + 1, comp);
	for(int i = 1; i <= n; i++){
		cout << an[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define oo 1000000000
#define ool 1000000000000000000
using namespace std;
int n, m;
vector<int> g[500100];
int t[500100], used[500100], an[500100];

bool dfs(int c){
	used[c] = true;
	for(int v: g[c]){
		if(t[v - 1] == t[c - 1]) return 1;
		if(!used[v]){
			if(dfs(v)) return 1;
		}
	}
	return 0;
}

bool dfs(){
	for(int i = 1; i <= n; i++){
		if(!used[i]){
			if(dfs(i)) return 1;
		}
	}
	return 0;
}

bool comp(int a, int b){
	return t[a - 1] < t[b - 1];
}

int main(){
	cin >> n >> m;
	for(int i = 0 ; i < m; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i = 0; i < n; i++){
		cin >> t[i];
		an[i] = i + 1;
	}
	if(dfs()){
		cout << -1 << endl;
		return 0;
	}
	sort(an, an + n, comp);
	for(int i = 0; i < n; i++){
		cout << an[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define oo 1000000000
#define ool 1000000000000000000
using namespace std;
int n, m;
vector<int> g[500100], an[500100];
int t[500100], used[500100];

bool comp(int a, int b){
	return t[a] < t[b];
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin >> n >> m;
	for(int i = 0 ; i < m; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i = 1; i <= n; i++){
		cin >> t[i];
		an[t[i]].pb(i);
	}

	for(int i = 1; i <= n; i++){
		if(t[i] > g[i].size() + 1){
			cout << -1 << endl;
			return 0;
		}
		for(int v : g[i]){
			if(t[v] == t[i]){
				cout << -1 << endl;
				return 0;
			}
			used[t[v]] = 1;
		}
		for(int j = 1; j < t[i]; j++){
			if(used[j] == 0){
				cout << -1 << endl;
				return 0;
			}
		}
		for(int v : g[i]){
			used[t[v]] = 0;
		}
	}

	for(int i = 1; i <= n; i++){
		for(int j: an[i]) cout << j << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define oo 1000000000
#define ool 1000000000000000000
using namespace std;
int n, m;
vector<int> g[500100];
int t[500100], used[500100], an[500100];

bool comp(int a, int b){
	return t[a] < t[b];
}

int main(){
	cin >> n >> m;
	for(int i = 0 ; i < m; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i = 1; i <= n; i++){
		cin >> t[i];
		an[i] = i;
	}

	for(int i = 1; i <= n; i++){
		for(int v : g[i]){
			if(t[v] == t[i]){
				cout << -1 << endl;
				return 0;
			}
			used[t[v]] = 1;
		}
		for(int j = 1; j < t[i]; j++){
			if(used[j] == 0){
				cout << -1 << endl;
				return 0;
			}
		}
		for(int v : g[i]){
			used[t[v]] = 0;
		}
	}

	sort(an + 1, an + n + 1, comp);
	for(int i = 1; i <= n; i++){
		cout << an[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define oo 1000000000
#define ool 1000000000000000000
using namespace std;
int n, m;
vector<int> g[500100];
int t[500100], used[500100], an[500100];

bool comp(int a, int b){
	return t[a] < t[b];
}

int main(){
	cin >> n >> m;
	for(int i = 0 ; i < m; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i = 1; i <= n; i++){
		cin >> t[i];
		an[i] = i;
	}

	for(int i = 1; i <= n; i++){
		if(t[i] > g[i].size() + 1){
			cout << -1 << endl;
			return 0;
		}
		for(int v : g[i]){
			if(t[v] == t[i]){
				cout << -1 << endl;
				return 0;
			}
			used[t[v]] = 1;
		}
		for(int j = 1; j < t[i]; j++){
			if(used[j] == 0){
				cout << -1 << endl;
				return 0;
			}
		}
		for(int v : g[i]){
			used[t[v]] = 0;
		}
	}

	sort(an + 1, an + n + 1, comp);
	for(int i = 1; i <= n; i++){
		cout << an[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
#define DEBUG puts("Here is a BUG")
#define MEM(a,b) memset((a),(b),sizeof(a))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define PI 3.1415926535897932626
#define all(a) a.begin(),a.end()
typedef long long ll;
using namespace std;
const double eps=1e-8;
const int MAXN=(int)1e5+5;
const int MOD=(int)1e9+7;
const int INF=0x3f3f3f3f;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
vector<int>G[MAXN];
vector<pair<int,int> >p;
int used[MAXN];
int n,m,a,b;
int f(int x)
{
    vector<int>q;
    for (int i = 0; i < G[x].size(); i++)if(used[G[x][i]])q.push_back(used[G[x][i]]);
    sort(all(q));
    for (int i = 0; i < q.size(); i++)
    {
        if(q[i]!=i+1)return i+1;
    }
    return q.size()+1;
}
void solve()
{
    sort(all(p));
    rep(i,0,n)
    {
        int x=f(p[i].second);
        if(x!=p[i].first){cout<<-1<<endl;return;}
        used[p[i].second]=p[i].first;
    }
    rep(i,0,n)cout<<p[i].second<<" ";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    rep(i,0,m)
    {
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i,1,n+1)
    {
        cin>>a;
        p.push_back(make_pair(a,i));
    }
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

set<int> g[44];
int n, m;

void off(ll &mask, int who)
{
    mask &= ~(1LL << who);
}

void on(ll &mask, int who)
{
    mask |= (1LL << who);
}

int mx;
int dp[1 << 20];
int dfs(int u, ll mask, int ans)
{
    // printf("%d %lld %d\n", u, mask, ans);
    if (u == m) {
        mx = max(mx, ans);
        return ans;
    }

    int right = mask >> (m / 2);
    if (u > m / 2 && dp[right] != -1) {
mx=max(mx ,dp[right]+ans);
        return dp[right];
}

    if (((mask >> u) & 1) == 0)
        return dp[right] = max(dp[right], dfs(u + 1, mask, ans));
    else {
        // pick
        // set self + connected bits to off
        ll orig = mask;
        off(mask, u);
        for (auto v : g[u])
            off(mask, v);
        int ret1 = dfs(u + 1, mask, ans + 1);
        mask = orig;

        // don't pick
        int ret2 = dfs(u + 1, mask, ans);

        return dp[right] = max(dp[right], max(ret1, ret2));
    }
}

int main()
{
    scanf("%d %d", &n, &m);
    memset(dp, -1, sizeof(dp));

    int idx = 0;
    unordered_map<string, int> nameMapping;
    set<int> collection;
    for (int i = 0; i <= n; i++) {
        int command;
        char name[44];
        if (i < n)
            scanf("%d", &command);
        if (i == n || command == 1) {
            for (auto u : collection)
                for (auto v : collection)
                    if (u != v)
                        g[u].insert(v), g[v].insert(u); /*printf("%d - %d\n", u, v)*/
            collection.clear();
        } else {
            scanf("%s", name);
            if (nameMapping.find(name) == nameMapping.end())
                nameMapping[name] = idx++;

            int id = nameMapping[name];
            collection.insert(id);
        }
    }

    ll mask = (1LL << m) - 1;
    mx = 0;
    dfs(0, mask, 0);

    printf("%d\n", mx);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

set<int> g[44];
int n, m;

void off(ll &mask, int who)
{
    mask &= ~(1LL << who);
}

void on(ll &mask, int who)
{
    mask |= (1LL << who);
}

int mx;
int dp[1 << 20];
int dfs(int u, ll mask, int ans)
{
    // printf("%d %lld %d\n", u, mask, ans);
    if (u == m) {
        mx = max(mx, ans);
        return ans;
    }

    int right = mask >> (m / 2);
    if (u > m / 2 && dp[right] != -1) {
ans=max(ans,dp[right]+ans);
        return dp[right];
}

    if (((mask >> u) & 1) == 0)
        return dp[right] = max(dp[right], dfs(u + 1, mask, ans));
    else {
        // pick
        // set self + connected bits to off
        ll orig = mask;
        off(mask, u);
        for (auto v : g[u])
            off(mask, v);
        int ret1 = dfs(u + 1, mask, ans + 1);
        mask = orig;

        // don't pick
        int ret2 = dfs(u + 1, mask, ans);

        return dp[right] = max(dp[right], max(ret1, ret2));
    }
}

int main()
{
    scanf("%d %d", &n, &m);
    memset(dp, -1, sizeof(dp));

    int idx = 0;
    unordered_map<string, int> nameMapping;
    set<int> collection;
    for (int i = 0; i <= n; i++) {
        int command;
        char name[44];
        if (i < n)
            scanf("%d", &command);
        if (i == n || command == 1) {
            for (auto u : collection)
                for (auto v : collection)
                    if (u != v)
                        g[u].insert(v), g[v].insert(u); /*printf("%d - %d\n", u, v)*/
            collection.clear();
        } else {
            scanf("%s", name);
            if (nameMapping.find(name) == nameMapping.end())
                nameMapping[name] = idx++;

            int id = nameMapping[name];
            collection.insert(id);
        }
    }

    ll mask = (1LL << m) - 1;
    mx = 0;
    dfs(0, mask, 0);

    printf("%d\n", mx);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

set<int> g[44];
int n, m;

void off(ll &mask, int who)
{
    mask &= ~(1LL << who);
}

void on(ll &mask, int who)
{
    mask |= (1LL << who);
}

int mx;
int dp[1 << 20];
int dfs(int u, ll mask, int ans)
{
    // printf("%d %lld %d\n", u, mask, ans);
    if (u == m) {
        mx = max(mx, ans);
        return ans;
    }

    int right = mask >> (m / 2);
    if (u > m / 2 && dp[right] != -1) {
mx=max(mx ,dp[right]+ans);
        return dp[right];
}

    if (((mask >> u) & 1) == 0)
        return dfs(u + 1, mask, ans);
    else {
        // pick
        // set self + connected bits to off
        ll orig = mask;
        off(mask, u);
        for (auto v : g[u])
            off(mask, v);
        int ret1 = dfs(u + 1, mask, ans + 1);
        mask = orig;

        // don't pick
        int ret2 = dfs(u + 1, mask, ans);

        return dp[right] = max(dp[right], max(ret1, ret2));
    }
}

int main()
{
    scanf("%d %d", &n, &m);
    memset(dp, -1, sizeof(dp));

    int idx = 0;
    unordered_map<string, int> nameMapping;
    set<int> collection;
    for (int i = 0; i <= n; i++) {
        int command;
        char name[44];
        if (i < n)
            scanf("%d", &command);
        if (i == n || command == 1) {
            for (auto u : collection)
                for (auto v : collection)
                    if (u != v)
                        g[u].insert(v), g[v].insert(u); /*printf("%d - %d\n", u, v)*/
            collection.clear();
        } else {
            scanf("%s", name);
            if (nameMapping.find(name) == nameMapping.end())
                nameMapping[name] = idx++;

            int id = nameMapping[name];
            collection.insert(id);
        }
    }

    ll mask = (1LL << m) - 1;
    mx = 0;
    dfs(0, mask, 0);

    printf("%d\n", mx);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

set<int> g[44];
int n, m;

void off(ll &mask, int who)
{
    mask &= ~(1LL << who);
}

void on(ll &mask, int who)
{
    mask |= (1LL << who);
}

int mx;
int dp[1 << 20];
int dfs(int u, ll mask, int ans)
{
    // printf("%d %lld %d\n", u, mask, ans);
    if (u == m) {
        mx = max(mx, ans);
        return ans;
    }

    if (((mask >> u) & 1) == 0)
        return dfs(u + 1, mask, ans);
    else {
        // pick
        // set self + connected bits to off
        ll orig = mask;
        off(mask, u);
        for (auto v : g[u])
            off(mask, v);
        int ret1 = dfs(u + 1, mask, ans + 1);
        mask = orig;

        // don't pick
        int ret2 = dfs(u + 1, mask, ans);

        return max(ret1, ret2);
    }
}

int main()
{
    scanf("%d %d", &n, &m);
    memset(dp, -1, sizeof(dp));

    int idx = 0;
    unordered_map<string, int> nameMapping;
    set<int> collection;
    for (int i = 0; i <= n; i++) {
        int command;
        char name[44];
        if (i < n)
            scanf("%d", &command);
        if (i == n || command == 1) {
            for (auto u : collection)
                for (auto v : collection)
                    if (u != v)
                        g[u].insert(v), g[v].insert(u); /*printf("%d - %d\n", u, v)*/
            collection.clear();
        } else {
            scanf("%s", name);
            if (nameMapping.find(name) == nameMapping.end())
                nameMapping[name] = idx++;

            int id = nameMapping[name];
            collection.insert(id);
        }
    }

    ll mask = (1LL << m) - 1;
    mx = 0;
    dfs(0, mask, 0);

    printf("%d\n", mx);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

set<int> g[44];
int n, m;

void off(ll &mask, int who)
{
    mask &= ~(1LL << who);
}

void on(ll &mask, int who)
{
    mask |= (1LL << who);
}

int mx;
int dp[1 << 20];
int dfs(int u, ll mask, int ans)
{
    // printf("%d %lld %d\n", u, mask, ans);
    if (u == m) {
        mx = max(mx, ans);
        return ans;
    }

    int right = mask >> (m / 2);
    if (u > m / 2 && dp[right] != -1)
        return dp[right];

    if (((mask >> u) & 1) == 0)
        return dp[right] = max(dp[right], dfs(u + 1, mask, ans));
    else {
        // pick
        // set self + connected bits to off
        ll orig = mask;
        off(mask, u);
        for (auto v : g[u])
            off(mask, v);
        int ret1 = dfs(u + 1, mask, ans + 1);
        mask = orig;

        // don't pick
        int ret2 = dfs(u + 1, mask, ans);

        return dp[right] = max(dp[right], max(ret1, ret2));
    }
}

int main()
{
    scanf("%d %d", &n, &m);
    memset(dp, -1, sizeof(dp));

    int idx = 0;
    unordered_map<string, int> nameMapping;
    set<int> collection;
    for (int i = 0; i <= n; i++) {
        int command;
        char name[44];
        if (i < n)
            scanf("%d", &command);
        if (i == n || command == 1) {
            for (auto u : collection)
                for (auto v : collection)
                    if (u != v)
                        g[u].insert(v), g[v].insert(u); /*printf("%d - %d\n", u, v)*/
            collection.clear();
        } else {
            scanf("%s", name);
            if (nameMapping.find(name) == nameMapping.end())
                nameMapping[name] = idx++;

            int id = nameMapping[name];
            collection.insert(id);
        }
    }

    ll mask = (1LL << m) - 1;
    mx = 0;
    dfs(0, mask, 0);

    printf("%d\n", mx);

    return 0;
}


#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long lli;

int n, m, k;
map<string, int> d;
bool e[40][40];
int st[40];
int d1[1 << 20], d2[1 << 20];
vector<int> l, r;

int f(int h) {
	if (!h) return 0;
	if (d1[h] >= 0) return d1[h];
	int ret = 0;
	for (int i = 0; i < l.size(); i++) if (h&(1 << i)) {
		ret = max(ret, f(h&st[i]) + 1);
	}
	return d1[h] = ret;
}

int g(int h) {
	if (!h) return 0;
	if (d2[h] >= 0) return d2[h];
	int ret = 0;
	for (int i = 0; i < r.size(); i++) if (h&(1 << i)) {
		ret = max(ret, g(h&st[i + m / 2]) + 1);
	}
	return d2[h] = ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	string s;
	lli cur = 0;
	for (int i = 0; i < n; i++) {
		int q;
		cin >> q;
		if (q == 1) {
			for (int j = 0; j < k; j++) if (cur&(1LL << j)) {
				for (int t = j + 1; t < k; t++) if (cur&(1LL << t)) {
					e[j][t] = e[t][j] = true;
				}
			}
			cur = 0;
		}
		else {
			cin >> s;
			if (!d.count(s)) d[s] = k++;
			cur |= (1LL << d[s]);
		}
	}
	for (int i = 0; i < k; i++) if (cur&(1LL << i)) {
		for (int j = i + 1; j < k; j++) if (cur&(1LL << j)) {
			e[i][j] = e[j][i] = true;
		}
	}
	for (int i = 0; i < m; i++) {
		if (i < m / 2) l.push_back(i);
		else r.push_back(i);
	}
	for (int i = 0; i < l.size(); i++) {
		for (int j = 0; j < l.size(); j++) if (i != j && !e[l[i]][l[j]])
			st[i] |= (1 << j);
	}
	for (int i = 0; i < r.size(); i++) {
		for (int j = 0; j < r.size(); j++) if (i != j && !e[r[i]][r[j]]) {
			st[i + m / 2] |= (1 << j);
		}
	}
	memset(d1, -1, sizeof(d1));
	memset(d2, -1, sizeof(d2));
	int res = 0;
	for (int i = 0; i < (1 << r.size()); i++) {
		int to = (1LL << (m / 2)) - 1;
		for (int j = 0; j < r.size(); j++) if (i&(1 << j)) {
			to &= st[j + m / 2];
		}
		res = max(res, f(to) + g(i));
	}
	cout << res << "\n";
	return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long lli;

int n, m, k;
map<string, int> d;
bool e[40][40];

int res;

void dfs(vector<int>& cand, int cnt) {
	if (cnt + cand.size() <= res) return;
	if (cnt > res) res = cnt;
	for (int i = 0; i < cand.size(); i++) {
		vector<int> nxt;
		for (int j = 0; j < cand.size(); j++) if (i != j) {
			if (!e[cand[i]][cand[j]])
				nxt.push_back(cand[j]);
		}
		dfs(nxt, cnt + 1);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	string s;
	lli cur = 0;
	for (int i = 0; i < n; i++) {
		int q;
		cin >> q;
		if (q == 1) {
			for (int j = 0; j < k; j++) if(cur&(1LL<<j)) {
				for (int t = j + 1; t < k; t++) if(cur&(1LL<<t)) {
					e[j][t] = e[t][j] = true;
				}
			}
			cur = 0;
		}
		else {
			cin >> s;
			if (!d.count(s)) d[s] = k++;
			cur |= (1LL << d[s]);
		}
	}
	for (int i = 0; i < k; i++) if (cur&(1LL << i)) {
		for (int j = i + 1; j < k; j++) if (cur&(1LL << j)) {
			e[i][j] = e[j][i] = true;
		}
	}
	vector<int> v;
	for (int i = 0; i < k; i++)
		v.push_back(i);
	dfs(v, 0);
	cout << res << "\n";
	return 0;
}


#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long lli;

int n, m, k;
map<string, int> d;
bool e[40][40];
int st[40];
int d1[1 << 20], d2[1 << 20];
vector<int> l, r;

int f(int h) {
	if (!h) return 0;
	if (d1[h] >= 0) return d1[h];
	int ret = 0;
	for (int i = 0; i < l.size(); i++) if (h&(1 << i)) {
		ret = max(ret, f(h&st[i]) + 1);
	}
	return d1[h] = ret;
}

int g(int h) {
	if (!h) return 0;
	if (d2[h] >= 0) return d2[h];
	int ret = 0;
	for (int i = 0; i < r.size(); i++) if (h&(1 << i)) {
		ret = max(ret, g(h&st[i + m / 2]) + 1);
	}
	return d2[h] = ret;
}

int lm[20];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	string s;
	lli cur = 0;
	for (int i = 0; i < n; i++) {
		int q;
		cin >> q;
		if (q == 1) {
			for (int j = 0; j < k; j++) if (cur&(1LL << j)) {
				for (int t = j + 1; t < k; t++) if (cur&(1LL << t)) {
					e[j][t] = e[t][j] = true;
				}
			}
			cur = 0;
		}
		else {
			cin >> s;
			if (!d.count(s)) d[s] = k++;
			cur |= (1LL << d[s]);
		}
	}
	for (int i = 0; i < k; i++) if (cur&(1LL << i)) {
		for (int j = i + 1; j < k; j++) if (cur&(1LL << j)) {
			e[i][j] = e[j][i] = true;
		}
	}
	for (int i = 0; i < m; i++) {
		if (i < m / 2) l.push_back(i);
		else r.push_back(i);
	}
	for (int i = 0; i < l.size(); i++) {
		for (int j = 0; j < l.size(); j++) if (i != j && !e[l[i]][l[j]])
			st[i] |= (1 << j);
	}
	for (int i = 0; i < r.size(); i++) {
		for (int j = 0; j < r.size(); j++) if (i != j && !e[r[i]][r[j]]) {
			st[i + m / 2] |= (1 << j);
		}
		for (int j = 0; j < l.size(); j++) if (!e[r[i]][l[j]])
			lm[i] |= (1 << j);
	}
	memset(d1, -1, sizeof(d1));
	memset(d2, -1, sizeof(d2));
	int res = 0;
	for (int i = 0; i < (1 << r.size()); i++) {
		int to = (1LL << (m / 2)) - 1;
		for (int j = 0; j < r.size(); j++) if (i&(1 << j)) {
			to &= lm[j];
		}
		res = max(res, f(to) + g(i));
	}
	cout << res << "\n";
	return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long lli;

class p {
public:
	int l, r;
	p(int l, int r)
		:l(l), r(r)
	{}
};

bool cmp(const p &i, const p &j) {
	return i.r < j.r;
}

int n, m, k;
map<string, int> d;

int L[40], R[40];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	string s;
	lli cur = 0;
	for (int i = 1; i <= n; i++) {
		int q;
		cin >> q;
		if (q == 1) {
			for (int j = 0; j < k; j++) if(cur&(1LL<<j)) {
				if (!L[j]) L[j] = i;
				R[j] = i;
			}
			cur = 0;
		}
		else {
			cin >> s;
			if (!d.count(s)) d[s] = k++;
			cur |= (1LL << d[s]);
		}
	}
	for (int i = 0; i < k; i++) if (cur&(1LL << i)) {
		if (!L[i]) L[i] = n + 1;
		R[i] = n + 1;
	}
	vector<p> v;
	for (int i = 0; i < k; i++) {
		v.push_back(p(L[i], R[i]));
	}
	sort(v.begin(), v.end(), cmp);
	int res = 1, ed = v[0].r;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].l > ed) {
			res++; ed = v[i].r;
		}
	}
	cout << res << "\n";
	return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long lli;

int n, m, k;
map<string, int> d;
bool e[40][40];

int res;

void dfs(vector<int>& cand, int cnt) {
	if (cnt + cand.size() <= res) return;
	if (cnt > res) res = cnt;
	for (int i = 0; i < cand.size(); i++) {
		vector<int> nxt;
		for (int j = i + 1; j < cand.size(); j++) if (i != j) {
			if (!e[cand[i]][cand[j]])
				nxt.push_back(cand[j]);
		}
		dfs(nxt, cnt + 1);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	string s;
	lli cur = 0;
	for (int i = 0; i < n; i++) {
		int q;
		cin >> q;
		if (q == 1) {
			for (int j = 0; j < k; j++) if (cur&(1LL << j)) {
				for (int t = j + 1; t < k; t++) if (cur&(1LL << t)) {
					e[j][t] = e[t][j] = true;
				}
			}
			cur = 0;
		}
		else {
			cin >> s;
			if (!d.count(s)) d[s] = k++;
			cur |= (1LL << d[s]);
		}
	}
	for (int i = 0; i < k; i++) if (cur&(1LL << i)) {
		for (int j = i + 1; j < k; j++) if (cur&(1LL << j)) {
			e[i][j] = e[j][i] = true;
		}
	}
	vector<int> v;
	for (int i = 0; i < k; i++)
		v.push_back(i);
	dfs(v, 0);
	cout << res << "\n";
	return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long lli;

int n, m, k;
map<string, int> d;
bool e[40][40];

int res;

void dfs(vector<int>& cand, int cnt) {
	if (cnt + cand.size() <= res) return;
	if (cnt > res) res = cnt;
	for (int i = 0; i < cand.size(); i++) {
		vector<int> nxt;
		for (int j = i + 1; j < cand.size(); j++) {
			if (!e[cand[i]][cand[j]])
				nxt.push_back(cand[j]);
		}
		dfs(nxt, cnt + 1);
	}
}

lli st[40];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	string s;
	lli cur = 0;
	for (int i = 0; i < n; i++) {
		int q;
		cin >> q;
		if (q == 1) {
			for (int j = 0; j < k; j++) if (cur&(1LL << j)) {
				for (int t = j + 1; t < k; t++) if (cur&(1LL << t)) {
					e[j][t] = e[t][j] = true;
				}
			}
			cur = 0;
		}
		else {
			cin >> s;
			if (!d.count(s)) d[s] = k++;
			cur |= (1LL << d[s]);
		}
	}
	for (int i = 0; i < k; i++) if (cur&(1LL << i)) {
		for (int j = i + 1; j < k; j++) if (cur&(1LL << j)) {
			e[i][j] = e[j][i] = true;
		}
	}
	vector<int> v;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) if (e[i][j] || i == j) {
			st[i] |= (1LL << j);
		}
	}
	for (int i = 0; i < k; i++) {
		bool ok = true;
		for (int j = 0; j < k; j++) if (i != j) {
			if ((st[i] & st[j]) == st[j]) {
				if (st[i] != st[j]) {
					ok = false;
					break;
				}
				else if (i > j) {
					ok = false; break;
				}
			}
		}
		if (ok) v.push_back(i);
	}
	dfs(v, 0);
	cout << res << "\n";
	return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int n, m;
map<string, int> d;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	string s;
	int res = 0;
	for (int i = 0; i < n; i++) {
		int q;
		cin >> q;
		if (q == 1) {
			int mx = 0;
			for (map<string, int>::iterator it = d.begin(); it != d.end(); it++) {
				mx = max(mx, it->second);
			}
			res += mx;
			d.clear();
		}
		else {
			cin >> s;
			d[s]++;
		}
	}
	int mx = 0;
	for (map<string, int>::iterator it = d.begin(); it != d.end(); it++) {
		mx = max(mx, it->second);
	}
	res += mx;
	cout << res << "\n";
	return 0;
}


#include<bits/stdc++.h>
#define int int64_t
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MX 1005
#define endl '\n'
#define P pair<int,int>
#define mo int64_t(1e9+7)
using namespace std;
int n,m,a,b,ans;
set<string> sets;
set<string>::iterator ite;
string s;
main(){
	cin>>n>>m;
	while(n--){
		cin>>a;
		if(a==1) b++;
		if(a==2){
			cin>>s;
			ite = sets.find(s);
			if(b>0 && ite==sets.end()){
				b--;
				ans++;
				sets.insert(s);
			}
		}
	}
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<20],hp[1<<20],ans;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,n) no[i] |= (1ll<<i);
	REP(i,0,1<<min(20ll,n)) REP(j,0,min(20ll,n)) if(((1<<j)&i)==0) MAX(dp[no[j]|i],dp[i]+1);
	if(n<=20) return cout<<dp[(1<<n)-1],0;
	REP(i,20,n) if(!no[i]) hp[0]++;
	REP(i,0,1<<min(20ll,n-20)){
		REP(j,20,n) if(((1<<(j-20))&i)==0) MAX(hp[(no[j]>>20)|i],hp[i]+1);
		cnt = 0;
		REP(j,20,n) if((j-20)&i) cnt |= (no[j]&((1<<20)-1));
		MAX(ans,hp[i]+dp[cnt^((1<<20)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define int int64_t
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MX 100005
#define endl '\n'
#define P pair<int,int>
#define PP pair<string,P>
#define mo int64_t(1e9+7)
using namespace std;
int n,m,sum[MX],a,b,ans,g;
vector<P> v;
map<string,int> ma;
map<string,int>::iterator ite;
string s;
main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a==1) b++;
		sum[i] = b;
		if(a==2){
			cin>>s;
			ite = ma.find(s);
			if(ite==ma.end()){
				v.push_back(mp(i,i));
				ma[s]=g;
				g++;
			}
			else
				v[ma[s]].S=i;
		}
	}
	sort(v.begin(),v.end());
	for(int i=0,c;i<m;){
		c = 0;
		for(int j=i;j<m;j++){
			if(sum[v[j].F]>c){
				c++;
				ans = max(ans,c);
				while(j+1<m && v[j+1].F<=v[j].S) j++;
			}
			else j++;
		}
	}
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<21],hp[1<<21],ans;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,n) no[i] |= (1ll<<i);
	REP(i,0,1<<min(20ll,n)) REP(j,0,min(20ll,n)) if(((1<<j)&i)==0) MAX(dp[no[j]|i],dp[i]+1);
	if(n<=20) return cout<<dp[(1<<n)-1],0;
	REP(i,20,n) if(!no[i]) hp[0]++;
	REP(i,0,1<<min(20ll,n-20)){
		REP(j,20,n) if(((1<<(j-20))&i)==0) MAX(hp[(no[j]>>20)|i],hp[i]+1);
		cnt = 0;
		REP(j,20,n) if((j-20)&i) cnt |= (no[j]&((1<<20)-1));
		MAX(ans,hp[i]+dp[cnt^((1<<20)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<20],hp[1<<20],ans;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,n) no[i] |= (1ll<<i);
	REP(i,0,1<<min(20ll,n)) REP(j,0,min(20ll,n)) if(((1ll<<j)&i)==0) MAX(dp[no[j]|i],dp[i]+1);
	if(n<=20) return cout<<dp[(1<<n)-1],0;
	REP(i,20,n) if(!no[i]) hp[0]++;
	REP(i,0,1<<20){
		REP(j,20,n) if(((1<<(j>>20))&i)==0) MAX(hp[(no[j]>>20)|i],hp[i]+1);
		cnt = 0;
		REP(j,20,n) if((j>>20)&i) cnt |= (no[j]&((1<<20)-1));
		MAX(ans,hp[i]+dp[cnt^((1<<20)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<21],hp[1<<21],ans,nn;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n, nn = n/2;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,1ll<<nn) REP(j,0,nn) if(((1ll<<j)&i)==0) MAX(dp[(no[j]&((1ll<<nn)-1))|i],dp[i]+1);
	REP(i,0,1ll<<(n-nn)){
		cnt = 0;
		REP(j,0,n-nn)
			if(((1ll<<j)&i)==0) MAX(hp[(no[nn+j]>>nn)|i],hp[i]+1);
			else cnt |= (no[nn+j]&((1ll<<nn)-1));
		MAX(ans,hp[i]+dp[cnt^((1ll<<nn)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<21],hp[1<<21],ans,nn;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n, nn = n/2;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,1ll<<nn) REP(j,0,nn) if(((1ll<<j)&i)==0) MAX(dp[(no[j]&((1ll<<nn)-1))|i],dp[i]+1);
	REP(i,0,1ll<<(n-nn)){
		cnt = 0;
		REP(j,0,n-nn)
			if(((1ll<<j)&i)==0) MAX(hp[(no[nn+j]>>nn)|i],hp[i]+1);
			else cnt |= (no[j]&((1ll<<nn)-1));
		MAX(ans,hp[i]+dp[cnt^((1ll<<nn)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define int int64_t
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MX 100005
#define endl '\n'
#define P pair<int,int>
#define PP pair<string,P>
#define mo int64_t(1e9+7)
using namespace std;
int n,m,sum[MX],a,b,ans,g;
vector<P> v;
map<string,int> ma;
map<string,int>::iterator ite;
string s;
main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a==1) b++;
		sum[i] = b;
		if(a==2){
			getline(cin,s);
			ite = ma.find(s);
			if(ite==ma.end()){
				v.push_back(mp(i,i));
				ma[s]=g;
				g++;
			}
			else
				v[ma[s]].S=i;
		}
	}
	sort(v.begin(),v.end());
	for(int i=0,c;i<m;i++){
		c = 0;
		for(int j=i;j<m;j++){
			if(sum[v[j].F]>c){
				c++;
				ans = max(ans,c);
				while(j+1<m && v[j+1].F<=v[j].S) j++;
			}
		}
	}
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<20],hp[1<<20],ans;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,n) no[i] |= (1ll<<i);
	REP(i,0,1<<min(20ll,n)) REP(j,0,min(20ll,n)) if(((1ll<<j)&i)==0) MAX(dp[no[j]|i],dp[i]+1);
	if(n<=20) return cout<<dp[(1<<n)-1],0;
	REP(i,20,n) if(!no[i]) hp[0]++;
	REP(i,0,1<<min(20ll,n-20)){
		REP(j,20,n) if(((1<<(j>>20))&i)==0) MAX(hp[(no[j]>>20)|i],hp[i]+1);
		cnt = 0;
		REP(j,20,n) if((j>>20)&i) cnt |= (no[j]&((1<<20)-1));
		MAX(ans,hp[i]+dp[cnt^((1<<20)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<20],hp[1<<20],ans;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,n) no[i] |= (1ll<<i);
	REP(i,0,1<<min(20ll,n)) REP(j,0,min(20ll,n)) if(((1ll<<j)&i)==0) MAX(dp[no[j]|i],dp[i]+1);
	if(n<=20) return cout<<dp[(1<<n)-1],0;
	REP(i,20,n) if(!no[i]) hp[0]++;
	REP(i,0,1<<min(20ll,n-20)){
		REP(j,20,n) if(((1<<(j-20))&i)==0) MAX(hp[(no[j]>>20)|i],hp[i]+1);
		cnt = 0;
		REP(j,20,n) if((j>>20)&i) cnt |= (no[j]&((1<<20)-1));
		MAX(ans,hp[i]+dp[cnt^((1<<20)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<21],hp[1<<21],ans;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,n) no[i] |= (1ll<<i);
	REP(i,0,1<<min(20ll,n)) REP(j,0,min(20ll,n)) if(((1<<j)&i)==0) MAX(dp[(no[j]&((1<<20)-1))|i],dp[i]+1);
	if(n<=20) return cout<<dp[(1<<n)-1],0;
	REP(i,0,1<<(n-20)){
		cnt = 0;
		REP(j,20,n)
			if(((1<<(j-20))&i)==0) MAX(hp[(no[j]>>20)|i],hp[i]+1);
			else cnt |= (no[j]&((1<<20)-1));
		MAX(ans,hp[i]+dp[cnt^((1<<20)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<21],hp[1<<21],ans;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,1<<min(20ll,n)) REP(j,0,min(20ll,n)) if(((1<<j)&i)==0) MAX(dp[(no[j]&((1<<20)-1))|i],dp[i]+1);
	if(n<=20) return cout<<dp[(1<<n)-1],0;
	REP(i,20,n) if(!no[i]) hp[0]++;
	REP(i,0,1<<min(20ll,n-20)){
		cnt = 0;
		REP(j,20,n)
			if(((1<<(j-20))&i)==0) MAX(hp[(no[j]>>20)|i],hp[i]+1);
			else cnt |= (no[j]&((1<<20)-1));
		MAX(ans,hp[i]+dp[cnt^((1<<20)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<21],hp[1<<21],ans;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,1<<min(20ll,n)) REP(j,0,min(20ll,n)) if(((1<<j)&i)==0) MAX(dp[no[j]|i],dp[i]+1);
	if(n<=20) return cout<<dp[(1<<n)-1],0;
	REP(i,20,n) if(!no[i]) hp[0]++;
	REP(i,0,1<<min(20ll,n-20)){
		REP(j,20,n) if(((1<<(j-20))&i)==0) MAX(hp[(no[j]>>20)|i],hp[i]+1);
		cnt = 0;
		REP(j,20,n) if((1<<(j-20))&i) cnt |= (no[j]&((1<<20)-1));
		MAX(ans,hp[i]+dp[cnt^((1<<20)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<21],hp[1<<21],ans,nn,ok;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n, nn = n/2;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,n) no[i] ^= (1ll<<i);
	REP(i,0,1ll<<nn){
		ok = 1,cnt = 0;
		REP(j,0,nn) if((i>>j)&1){
			if(no[j]&i) ok = 0;
			cnt++;
			MAX(dp[i],dp[i^(1<<j)]);
		}
		if(ok) dp[i] = cnt;
	}
	REP(i,0,1ll<<(n-nn)){
		ok = 1,cnt = a = 0;
		REP(j,0,n-nn) if((i>>j)&1){
			if((no[j+nn]>>nn)&i) ok = 0;
			a |= (no[j+nn]&((1ll<<nn)-1));
			cnt++;
		}
		if(ok) MAX(ans,cnt+dp[a^((1ll<<nn)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define REP(i,j,k) for(int i=j;i<k;++i)
#define RREP(i,j,k) for(int i=(int)j-1;i>=k;--i)
#define int long long
#define pb emplace_back
#define P pair<int,int>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define sz(a) (int)(a).size()
#define MX 100005
#define oo 1e18
#define L d*2
#define R (d*2+1)
#define mid (l+r>>1)
#define Ls l,mid,d*2
#define Rs mid+1,r,d*2+1
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mo (int)(1e9+7)
#define IOS cin.tie(0) ,cout.tie(0), cout.sync_with_stdio(0)
using namespace std;
int t,n,a,cnt,no[45],dp[1<<21],hp[1<<21],ans;
string s;
map<string,int> m;
set<int> ss;
main(){
	IOS;
	cin>>t>>n;
	while(t--){
		cin>>a;
		if(a==1){
			for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
			ss.clear();
		}
		else{
			cin>>s;
			if(!m[s]) m[s] = ++cnt;
			ss.insert(m[s]);
		}
	}
	for(auto u:ss) for(auto uu:ss) no[u-1] |= (1ll<<(uu-1));
	REP(i,0,n) no[i] |= (1ll<<i);
	REP(i,0,1<<min(20ll,n)) REP(j,0,min(20ll,n)) if(((1<<j)&i)==0) MAX(dp[(no[j]&((1<<20)-1))|i],dp[i]+1);
	if(n<=20) return cout<<dp[(1<<n)-1],0;
	REP(i,20,n) if(!no[i]) hp[0]++;
	REP(i,0,1<<min(20ll,n-20)){
		cnt = 0;
		REP(j,20,n)
			if(((1<<(j-20))&i)==0) MAX(hp[(no[j]>>20)|i],hp[i]+1);
			else cnt |= (no[j]&((1<<20)-1));
		MAX(ans,hp[i]+dp[cnt^((1<<20)-1)]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define int int64_t
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MX 1005
#define endl '\n'
#define P pair<int,int>
#define mo int64_t(1e9+7)
using namespace std;
int n,m,a,b,ans;
set<string> sets;
set<string>::iterator ite;
string s;
main(){
	cin>>n>>m;
	while(n--){
		cin>>a;
		if(a==1) b++;
		if(a==2){
			getline(cin,s);
			ite = sets.find(s);
			if(b>0 && ite==sets.end()){
				b--;
				ans++;
				sets.insert(s);
			}
		}
	}
	cout<<ans<<"\n";
}


#include <bits/stdc++.h>

using namespace std;

typedef bitset<64> BS;

void bk(const vector<BS>& g, BS R, BS P, BS X, BS* ans) {
  if (P.none() && X.none()) {
    if (R.count() > ans->count()) *ans = R;
    return;
  }
  int q = (P | X)._Find_first();
  BS cands = P;
  for (size_t i = 0; i < g.size(); i++) {
    if (cands[i]) {
      R[i] = 1;
      bk(g, R, P & g[i], X & g[i], ans);
      R[i] = P[i] = 0, X[i] = 1;
    }
  }
}

int max_clique(const vector<BS>& g) {
  BS ans;
  bk(g, BS(), ~BS(), BS(), &ans);
  return ans.count();
}

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  set<int> se;
  map<string, int> mp;
  vector<BS> g(m);
  for (int i = 0; i < n; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      se.clear();
    } else {
      string s;
      cin >> s;
      if (!mp.count(s)) {
        int sz = mp.size();
        mp[s] = sz;
      }
      int d = mp[s];
      if (!se.count(d)){
        for (auto x : se) {
          g[x][d] = 1;
          g[d][x] = 1;
        }
      }
      se.insert(mp[s]);
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i != j) g[i][j] = ~g[i][j];
    }
  }
  cout << max_clique(g) << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  set<int> se;
  map<string, int> mp;
  vector<long long> g(m);
  for (int i = 0; i < n; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      se.clear();
    } else {
      string s;
      cin >> s;
      if (!mp.count(s)) {
        int sz = mp.size();
        mp[s] = sz;
      }
      int d = mp[s];
      if (!se.count(d)){
        for (auto x : se) {
          g[x] |= (1LL << d);
          g[d] |= (1LL << x);
        }
      }
      se.insert(mp[s]);
    }
  }
  int md = g.size() / 2;
  int sl = md, sr = g.size() - sl;
  vector<int> v1(1 << sl), v2(1 << sr);
  for (int i = 0; i < 1 << sl; i++) {
    bool ok = v1[i] == __builtin_popcount(i);
    for (int j = 0; j < sl; j++) {
      if (!((1 << j) & i)) {
        v1[i | 1 << j] = max(v1[i | 1 << j], v1[i] + ((g[j] & i) == 0 && ok));
      }
    }
  }
  for (int i = 0; i < 1 << sr; i++) {
    bool ok = v1[i] == __builtin_popcount(i);
    for (int j = 0; j < sr; j++) {
      if (!((1 << j) & i)) {
        v2[i | 1 << j] = max(v2[i | 1 << j], v2[i] + ((g[j + md] & ((1LL * i) << md)) == 0 && ok));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 1 << sl; i++) {
    long long mask = (1LL << g.size()) - 1;
    for (int j = 0; j < sl; j++) {
      if ((1 << j) & i) {
        mask &= ~g[j];
      }
    }
    long long t = (mask >> md);
    ans = max(ans, v1[i] + v2[t]);
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef bitset<64> BS;

void bk(const vector<BS>& g, BS R, BS P, BS X, BS* ans) {
  if (P.none() && X.none()) {
    if (R.count() > ans->count()) *ans = R;
    return;
  }
  int q = (P | X)._Find_first();
  BS cands = P & ~g[q];
  for (size_t i = 0; i < g.size(); i++) {
    if (cands[i]) {
      R[i] = 1;
      bk(g, R, P & g[i], X & g[i], ans);
      R[i] = P[i] = 0, X[i] = 1;
    }
  }
}

int max_clique(const vector<BS>& g) {
  BS ans;
  bk(g, BS(), ~BS(), BS(), &ans);
  return ans.count();
}

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  set<int> se;
  map<string, int> mp;
  vector<BS> g(m);
  for (int i = 0; i < n; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      se.clear();
    } else {
      string s;
      cin >> s;
      if (!mp.count(s)) {
        int sz = mp.size();
        mp[s] = sz;
      }
      int d = mp[s];
      if (!se.count(d)){
        for (auto x : se) {
          g[x][d] = 1;
          g[d][x] = 1;
        }
      }
      se.insert(mp[s]);
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i != j) g[i][j] = ~g[i][j];
    }
  }
  cout << max_clique(g) << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  set<int> se;
  map<string, int> mp;
  vector<long long> g(m);
  for (int i = 0; i < n; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      se.clear();
    } else {
      string s;
      cin >> s;
      if (!mp.count(s)) {
        int sz = mp.size();
        mp[s] = sz;
      }
      int d = mp[s];
      if (!se.count(d)){
        for (auto x : se) {
          g[x] |= (1LL << d);
          g[d] |= (1LL << x);
        }
      }
      se.insert(mp[s]);
    }
  }
  int md = g.size() / 2;
  int sl = md, sr = g.size() - sl;
  vector<int> v1(1 << sl), v2(1 << sr);
  for (int i = 0; i < 1 << sl; i++) {
    bool ok = v1[i] == __builtin_popcount(i);
    for (int j = 0; j < sl; j++) {
      if (!((1 << j) & i)) {
        v1[i | 1 << j] = max(v1[i | 1 << j], v1[i] + ((g[j] & i) == 0 && ok));
      }
    }
  }
  for (int i = 0; i < 1 << sr; i++) {
    bool ok = v2[i] == __builtin_popcount(i);
    for (int j = 0; j < sr; j++) {
      if (!((1 << j) & i)) {
        v2[i | 1 << j] = max(v2[i | 1 << j], v2[i] + ((g[j + md] & ((1LL * i) << md)) == 0 && ok));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 1 << sl; i++) {
    long long mask = (1LL << g.size()) - 1;
    for (int j = 0; j < sl; j++) {
      if ((1 << j) & i) {
        mask &= ~g[j];
      }
    }
    long long t = (mask >> md);
    ans = max(ans, v1[i] + v2[t]);
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  set<int> se;
  map<string, int> mp;
  vector<long long> g(m);
  for (int i = 0; i < n; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      for (auto x : se) {
        for (auto y : se) {
          if (x != y) {
            g[x] |= (1LL << y);
            g[y] |= (1LL << x);
          }
        }
      }
      se.clear();
    } else {
      string s;
      cin >> s;
      if (!mp.count(s)) {
        int sz = mp.size();
        mp[s] = sz;
      }
      se.insert(mp[s]);
    }
  }
  int md = g.size() / 2;
  int sl = md, sr = g.size() - sl;
  vector<int> v1(1 << sl), v2(1 << sr);
  for (int i = 0; i < 1 << sl; i++) {
    if (v1[i] == __builtin_popcount(i)) {
      for (int j = 0; j < sl; j++) {
        if (!((1 << j) & i)) {
          v1[i | 1 << j] = max(v1[i | 1 << j], v1[i] + ((g[j] & i) == 0));
        }
      }
    }
  }
  for (int i = 0; i < 1 << sr; i++) {
    if (v2[i] == __builtin_popcount(i)) {
      for (int j = 0; j < sr; j++) {
        if (!((1 << j) & i)) {
          v2[i | 1 << j] = max(v2[i | 1 << j], v2[i] + ((g[j + md] & ((1LL * i) << md)) == 0));
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 1 << sl; i++) {
    long long mask = 0;
    for (int j = 0; j < sl; j++) {
      if ((1 << j) & i) {
        mask |= g[j];
      }
    }
    long long t = (mask >> md);
    ans = max(ans, v1[i] + v2[t]);
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  set<int> se;
  map<string, int> mp;
  vector<long long> g(m);
  for (int i = 0; i < n; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      se.clear();
    } else {
      string s;
      cin >> s;
      if (!mp.count(s)) {
        int sz = mp.size();
        mp[s] = sz;
      }
      int d = mp[s];
      if (!se.count(d)){
        for (auto x : se) {
          g[x] |= (1LL << d);
          g[d] |= (1LL << x);
        }
      }
      se.insert(mp[s]);
    }
  }
  int md = g.size() / 2;
  int sl = md, sr = g.size() - sl;
  vector<int> v1(1 << sl), v2(1 << sr);
  for (int i = 0; i < 1 << sl; i++) {
    if (v1[i] == __builtin_popcount(i)) {
      for (int j = 0; j < sl; j++) {
        if (!((1 << j) & i)) {
          v1[i | 1 << j] = max(v1[i | 1 << j], v1[i] + ((g[j] & i) == 0));
        }
      }
    }
  }
  for (int i = 0; i < 1 << sr; i++) {
    if (v2[i] == __builtin_popcount(i)) {
      for (int j = 0; j < sr; j++) {
        if (!((1 << j) & i)) {
          v2[i | 1 << j] = max(v2[i | 1 << j], v2[i] + ((g[j + md] & ((1LL * i) << md)) == 0));
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 1 << sl; i++) {
    long long mask = (1LL << g.size()) - 1;
    for (int j = 0; j < sl; j++) {
      if ((1 << j) & i) {
        mask &= ~g[j];
      }
    }
    long long t = (mask >> md);
    ans = max(ans, v1[i] + v2[t]);
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  set<int> se;
  map<string, int> mp;
  vector<long long> g(m);
  for (int i = 0; i < n; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      se.clear();
    } else {
      string s;
      cin >> s;
      if (!mp.count(s)) {
        int sz = mp.size();
        mp[s] = sz;
      }
      int d = mp[s];
      if (!se.count(d)){
        for (auto x : se) {
          g[x] |= (1LL << d);
          g[d] |= (1LL << x);
        }
      }
      se.insert(mp[s]);
    }
  }
  int md = g.size() / 2;
  int sl = md, sr = g.size() - sl;
  vector<int> v1(1 << sl), v2(1 << sr);
  for (int i = 0; i < 1 << sl; i++) {
    bool ok = v1[i] == __builtin_popcount(i);
    for (int j = 0; j < sl; j++) {
      if (!((1 << j) & i)) {
        v1[i | 1 << j] = max(v1[i | 1 << j], v1[i] + ((g[j] & i) == 0 && ok));
      }
    }
  }
  for (int i = 0; i < 1 << sr; i++) {
    bool ok = v1[i] == __builtin_popcount(i);
    if (v2[i] == __builtin_popcount(i)) {
      for (int j = 0; j < sr; j++) {
        if (!((1 << j) & i)) {
          v2[i | 1 << j] = max(v2[i | 1 << j], v2[i] + ((g[j + md] & ((1LL * i) << md)) == 0 && ok));
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 1 << sl; i++) {
    long long mask = (1LL << g.size()) - 1;
    for (int j = 0; j < sl; j++) {
      if ((1 << j) & i) {
        mask &= ~g[j];
      }
    }
    long long t = (mask >> md);
    ans = max(ans, v1[i] + v2[t]);
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

int ans, q, m, type, cnt; string t;
map<string, int> names;
vector<pii> v;
int adj[50][50];
vector<int> e[50];
long long ss[50];
long long mask;

void dfs(int v, int cur = 0) {
	if (v == m + 1) {
		ans = max(ans, cur);
		return;
	}

	if (((~mask) | ss[v]) == ~mask) {
		mask ^= (1LL << v);
		dfs(v + 1, cur + 1);
		mask ^= (1LL << v);
	}
	dfs(v + 1, cur);
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> q >> m;
	names.clear();
	for (int i = 0; i < q; i++) {
		cin >> type;
		if (type == 1) v.pb({1, -1});
		else {
			cin >> t;
			if (!names.count(t)) names[t] = ++cnt;
			v.pb({2, names[t]});
		}
	}
	v.pb({1, -1}); q++;

	long long bs = 0;
	for (int i = 0; i < q; i++) {
		cerr << v[i].fi << ' ' << v[i].se << '\n';
		if (v[i].fi == 1) {
			for (int x = 1; x <= m; x++) {
				if (bs & (1LL << x)) {
					for (int y = x + 1; y <= m; y++) {
						if (bs & (1LL << y)) adj[x][y] = adj[y][x] = 1;
					}
				}
			}
			bs = 0;
		}
		else bs |= (1LL << v[i].se);
	}

	for (int i = 1; i <= m; i++)
	for (int j = 1; j <= m; j++) if (adj[i][j]) e[i].pb(j), ss[i] |= (1LL << j);

	dfs(1);

	cout << ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

int ans, q, m, type; string t;
set<string> names;
vector<pii> v;
int cnt[50];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> q >> m;
	for (int i = 0; i < q; i++) {
		cin >> type;
		if (type == 1) v.pb({1, -1});
		else {
			cin >> t; names.insert(t);
			v.pb({2, names.size()});
		}
	}

	for (auto x : v) cerr << x.fi << ' ' << x.se << '\n';

	for (int i = 1; i < v.size(); i++) {
		if (v[i].fi == 1) {
			ans += *max_element(cnt, cnt + 50);
			memset(cnt, 0, sizeof(cnt));
		}
		else {
			cnt[v[i].se]++;
		}
	}

	ans += *max_element(cnt, cnt + 50);

	cout << ans;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 1
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt", r, stdin);
#define test cerr << "hi\n";
#define tr(x) cerr << #x << ' ' << x << '\n';
#define fi first
#define se second
#define HH1 402653289
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple <int, int, int>
#define npos string::npos
#define ll long long
#define ull unsigned long long

using namespace std;

#define MOD 1000000007LL
#define MAXN 100005

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

}
/*
12
lift: 11, 8
land: 7, 5

12
11, 5, 8, 7

(12+x) = x * 7
12+x = 7x; x = 12 / 6 = 2
*/


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

bool adj[50][50]; // 0-based
unordered_map<long long, int> dp1, dp2; // meet in the middle
int n;

void buildGraph() {
	int events; cin >> events >> n;
	map<string, int> m;
	set<int> cur;

	for (int i = 0, type; i < events; i++) {
		cin >> type;
		if (type == 1) {
			for (int x : cur) for (int y : cur) {
				if (x != y) adj[x][y] = 1;
			}
			cur.clear();
		}
		else {
			string name; cin >> name;
			if (!m.count(name)) {
				int k = m.size();
				m[name] = k;
			}
			cur.insert(m[name]);
		}
	}
	for (int x : cur) for (int y : cur) {
		if (x != y) adj[x][y] = adj[y][x] = 1;
	}
	for (auto op : m) {
		cerr << op.fi << ' ' << op.se << '\n';
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	buildGraph();

	int mi = n / 2;

	dp1[0] = dp2[0] = 0;

	for (long long bs = 1; bs < (1LL << mi); bs += 1LL) { // for first n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp1[bs] = max(dp1[bs], dp1[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp1[bs] = cur.size();

		tr(bs)
		tr(dp1[bs])
	}

	for (long long bs = (1LL << mi); bs < (1LL << n); bs += (1LL << mi)) { // for second n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = mi; node < n; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp2[bs] = max(dp2[bs], dp2[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp2[bs] = cur.size();

		tr(bs)
		tr(dp2[bs])
	}

	int ans = 0;

	for (long long bs = 0; bs < (1LL << mi); bs += 1LL) { // meet in the middle
		long long getHalf = ((1LL << (n - mi)) - 1) << mi;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				for (int i = mi; i < n; i++) {
					tr(node)
					tr(i)
					if (adj[node][i]) {
						getHalf &= (~(1LL << i));
					}
				}
			}
		}
		tr(bs)
		tr(getHalf)
		ans = max(ans, dp1[bs] + dp2[getHalf]);
	}

	cout << ans;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cerr << adj[i][j];
		cerr << '\n';
	}

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

bool adj[50][50]; // 0-based
unordered_map<long long, int> dp1, dp2; // meet in the middle
int n;

void buildGraph() {
	int events; cin >> events >> n;
	map<string, int> m;
	set<int> cur;

	for (int i = 0, type; i < events; i++) {
		cin >> type;
		if (type == 1) {
			for (int x : cur) for (int y : cur) {
				if (x != y) adj[x][y] = 1;
			}
			cur.clear();
		}
		else {
			string name; cin >> name;
			if (!m.count(name)) {
				int k = m.size();
				m[name] = k;
			}
			cur.insert(m[name]);
		}
	}
	for (int x : cur) for (int y : cur) {
		if (x != y) adj[x][y] = adj[y][x] = 1;
	}
	for (auto op : m) {
		cerr << op.fi << ' ' << op.se << '\n';
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	buildGraph();

	int mi = n / 2;

	dp1[0] = dp2[0] = 0;

	for (long long bs = 1; bs < (1LL << mi); bs += 1LL) { // for first n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp1[bs] = max(dp1[bs], dp1[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp1[bs] = cur.size();
	}

	for (long long bs = (1LL << mi); bs < (1LL << n); bs += (1LL << mi)) { // for second n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = mi; node < n; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp2[bs] = max(dp2[bs], dp2[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp2[bs] = cur.size();
	}

	if (n == 40) exit(0);

	int ans = 0;

	for (long long bs = 0; bs < (1LL << mi); bs += 1LL) { // meet in the middle
		long long getHalf = ((1LL << (n - mi)) - 1) << mi;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				for (int i = mi; i < n; i++) {
					if (adj[node][i]) {
						getHalf &= (~(1LL << i));
					}
				}
			}
		}
		ans = max(ans, dp1[bs] + dp2[getHalf]);
	}

	cout << ans;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cerr << adj[i][j];
		cerr << '\n';
	}

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

int ans, q, m, type, cnt; string t;
map<string, int> names;
vector<pii> v;
int adj[50][50];
vector<int> e[50];
long long mask;

void dfs(int v, int cur = 0) {
	if (v == m + 1) {
		ans = max(ans, cur);
		return;
	}

	int ok = 1;
	for (int u : e[v]) {
		if (mask & (1LL << u)) {
			ok = 0; break;
		}
	}

	if (ok) {
		mask ^= (1LL << v);
		dfs(v + 1, cur + 1);
		mask ^= (1LL << v);
	}
	dfs(v + 1, cur);
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> q >> m;
	names.clear();
	for (int i = 0; i < q; i++) {
		cin >> type;
		if (type == 1) v.pb({1, -1});
		else {
			cin >> t;
			if (!names.count(t)) names[t] = ++cnt;
			v.pb({2, names[t]});
		}
	}
	v.pb({1, -1}); q++;

	long long bs = 0;
	for (int i = 0; i < q; i++) {
		cerr << v[i].fi << ' ' << v[i].se << '\n';
		if (v[i].fi == 1) {
			for (int x = 1; x <= m; x++) {
				if (bs & (1LL << x)) {
					for (int y = x + 1; y <= m; y++) {
						if (bs & (1LL << y)) adj[x][y] = adj[y][x] = 1;
					}
				}
			}
			bs = 0;
		}
		else bs |= (1LL << v[i].se);
	}

	for (int i = 1; i <= m; i++)
	for (int j = 1; j <= m; j++) if (adj[i][j]) e[i].pb(j);

	dfs(1);

	cout << ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

bool adj[50][50]; // 0-based
int dp1[1 << 22], dp2[1 << 22];
int n;

void buildGraph() {
	int events; cin >> events >> n;
	map<string, int> m;
	set<int> cur;

	for (int i = 0, type; i < events; i++) {
		cin >> type;
		if (type == 1) {
			for (int x : cur) for (int y : cur) {
				if (x != y) adj[x][y] = 1;
			}
			cur.clear();
		}
		else {
			string name; cin >> name;
			if (!m.count(name)) {
				int k = m.size();
				m[name] = k;
			}
			cur.insert(m[name]);
		}
	}
	for (int x : cur) for (int y : cur) {
		if (x != y) adj[x][y] = adj[y][x] = 1;
	}
	for (auto op : m) {
		cerr << op.fi << ' ' << op.se << '\n';
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	buildGraph();

	int mi = n / 2;

	dp1[0] = dp2[0] = 0;

	for (long long bs = 1; bs < (1LL << mi); bs += 1LL) { // for first n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp1[bs] = max(dp1[bs], dp1[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp1[bs] = cur.size();
	}

	for (long long bs = (1LL << mi); bs < (1LL << n); bs += (1LL << mi)) { // for second n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = mi; node < n; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp2[bs >> mi] = max(dp2[bs >> mi], dp2[(bs ^ (1LL << node)) >> mi]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp2[bs >> mi] = cur.size();
	}

	int ans = 0;

	for (long long bs = 0; bs < (1LL << mi); bs += 1LL) { // meet in the middle
		long long getHalf = ((1LL << (n - mi)) - 1) << mi;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				for (int i = mi; i < n; i++) {
					if (adj[node][i]) {
						getHalf &= (~(1LL << i));
					}
				}
			}
		}
		ans = max(ans, dp1[bs] + dp2[getHalf >> mi]);
	}

	cout << ans;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cerr << adj[i][j];
		cerr << '\n';
	}

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

int ans, q, m, type, cnt; string t;
map<string, int> names;
vector<pii> v;
int adj[50][50];
vector<int> e[50];
long long mask;

void dfs(int v, int cur = 0) {
	if (v == m + 1) {
		ans = max(ans, cur);
		return;
	}

	int ok = 1;
	for (int u : e[v]) {
		if (mask & (1LL << u)) ok = 0;
	}

	if (ok) {
		mask ^= (1LL << v);
		dfs(v + 1, cur + 1);
		mask ^= (1LL << v);
	}
	dfs(v + 1);
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> q >> m;
	names.clear();
	for (int i = 0; i < q; i++) {
		cin >> type;
		if (type == 1) v.pb({1, -1});
		else {
			cin >> t;
			if (!names.count(t)) names[t] = ++cnt;
			v.pb({2, names[t]});
		}
	}
	v.pb({1, -1}); q++;

	long long bs = 0;
	for (int i = 0; i < q; i++) {
		cerr << v[i].fi << ' ' << v[i].se << '\n';
		if (v[i].fi == 1) {
			for (int x = 1; x <= m; x++) {
				if (bs & (1LL << x)) {
					for (int y = x + 1; y <= m; y++) {
						if (bs & (1LL << y)) adj[x][y] = adj[y][x] = 1;
					}
				}
			}
			bs = 0;
		}
		else bs |= (1LL << v[i].se);
	}

	for (int i = 1; i <= m; i++)
	for (int j = 1; j <= m; j++) if (adj[i][j]) e[i].pb(j);

	dfs(1);

	cout << ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

bool adj[50][50]; // 0-based
unordered_map<long long, int> dp1, dp2; // meet in the middle
int n;

void buildGraph() {
	int events; cin >> events >> n;
	map<string, int> m;
	set<int> cur;

	for (int i = 0, type; i < events; i++) {
		cin >> type;
		if (type == 1) {
			for (int x : cur) for (int y : cur) {
				if (x != y) adj[x][y] = 1;
			}
			cur.clear();
		}
		else {
			string name; cin >> name;
			if (!m.count(name)) {
				int k = m.size();
				m[name] = k;
			}
			cur.insert(m[name]);
		}
	}
	for (int x : cur) for (int y : cur) {
		if (x != y) adj[x][y] = adj[y][x] = 1;
	}
	for (auto op : m) {
		cerr << op.fi << ' ' << op.se << '\n';
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	buildGraph();

	int mi = n / 2;

	dp1[0] = dp2[0] = 0;

	for (long long bs = 1; bs < (1LL << mi); bs += 1LL) { // for first n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp1[bs] = max(dp1[bs], dp1[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp1[bs] = cur.size();

		tr(bs)
		tr(dp1[bs])
	}

	if (n == 40) exit(0)

	for (long long bs = (1LL << mi); bs < (1LL << n); bs += (1LL << mi)) { // for second n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = mi; node < n; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp2[bs] = max(dp2[bs], dp2[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp2[bs] = cur.size();
	}

	int ans = 0;

	for (long long bs = 0; bs < (1LL << mi); bs += 1LL) { // meet in the middle
		long long getHalf = ((1LL << (n - mi)) - 1) << mi;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				for (int i = mi; i < n; i++) {
					if (adj[node][i]) {
						getHalf &= (~(1LL << i));
					}
				}
			}
		}
		ans = max(ans, dp1[bs] + dp2[getHalf]);
	}

	cout << ans;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cerr << adj[i][j];
		cerr << '\n';
	}

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

bool adj[50][50]; // 0-based
int dp1[1 << 22], dp2[1 << 22];
int n;

void buildGraph() {
	int events; cin >> events >> n;
	map<string, int> m;
	set<int> cur;

	for (int i = 0, type; i < events; i++) {
		cin >> type;
		if (type == 1) {
			for (int x : cur) for (int y : cur) {
				if (x != y) adj[x][y] = 1;
			}
			cur.clear();
		}
		else {
			string name; cin >> name;
			if (!m.count(name)) {
				int k = m.size();
				m[name] = k;
			}
			cur.insert(m[name]);
		}
	}
	for (int x : cur) for (int y : cur) {
		if (x != y) adj[x][y] = adj[y][x] = 1;
	}
	for (auto op : m) {
		cerr << op.fi << ' ' << op.se << '\n';
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	buildGraph();

	int mi = n / 2;

	dp1[0] = dp2[0] = 0;

	for (long long bs = 1; bs < (1LL << mi); bs += 1LL) { // for first n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp1[bs] = max(dp1[bs], dp1[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp1[bs] = cur.size();
	}

	for (long long bs = (1LL << mi); bs < (1LL << n); bs += (1LL << mi)) { // for second n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = mi; node < n; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp2[bs >> mi] = max(dp2[bs >> mi], dp2[(bs ^ (1LL << node)) >> mi]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp2[bs >> mi] = cur.size();
	}

	if (n == 40) exit(0);

	int ans = 0;

	for (long long bs = 0; bs < (1LL << mi); bs += 1LL) { // meet in the middle
		long long getHalf = ((1LL << (n - mi)) - 1) << mi;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				for (int i = mi; i < n; i++) {
					if (adj[node][i]) {
						getHalf &= (~(1LL << i));
					}
				}
			}
		}
		ans = max(ans, dp1[bs] + dp2[getHalf >> mi]);
	}

	cout << ans;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cerr << adj[i][j];
		cerr << '\n';
	}

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

int ans, q, m, type; string t;
map<string, int> names;
int cnt = 0;
vector<pii> v;
int fi[50], la[50];
vector<pii> seg;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> q >> m;
	names.clear();
	for (int i = 0; i < q; i++) {
		cin >> type;
		if (type == 1) v.pb({1, -1});
		else {
			cin >> t;
			if (!names.count(t)) names[t] = ++cnt;
			v.pb({2, names[t]});
		}
	}

	memset(fi, -1, sizeof(fi));

	for (auto x : v) cerr << x.fi << ' ' << x.se << '\n';
	cerr << "------\n";

	for (int i = 0, seen = -1; i < v.size(); i++) {
		if (v[i].fi == 1) seen = i;
		else {
			if (fi[v[i].se] == -1) fi[v[i].se] = seen;
			la[v[i].se] = seen;
		}
	}

	for (int i = 1; i <= m; i++) {
		seg.pb({fi[i], la[i]});
	}

	for (auto x : seg) cerr << x.fi << ' ' << x.se << '\n';

	sort(seg.begin(), seg.end(), [](pii x, pii y) {
		return x.se < y.se;
	});

	int ans = 0, cur = -1;

	for (auto x : seg) {
		if (cur < x.fi) cur = x.se, ans++;
	}

	cout << ans;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

bool adj[50][50]; // 0-based
unordered_map<long long, int> dp1, dp2; // meet in the middle
int n;

void buildGraph() {
	int events; cin >> events >> n;
	map<string, int> m;
	vector<int> cur;

	for (int i = 0, type; i < events; i++) {
		cin >> type;
		if (type == 1) {
			for (int x : cur) for (int y : cur) {
				if (x != y) adj[x][y] = 1;
			}
			cur.clear();
		}
		else {
			string name; cin >> name;
			if (!m.count(name)) {
				int k = m.size();
				m[name] = k;
			}
			cur.pb(m[name]);
		}
	}
	for (int x : cur) for (int y : cur) {
		if (x != y) adj[x][y] = adj[y][x] = 1;
	}
	for (auto op : m) {
		cerr << op.fi << ' ' << op.se << '\n';
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	buildGraph();

	int mi = n / 2;

	dp1[0] = dp2[0] = 0;

	for (long long bs = 1; bs < (1LL << mi); bs += 1LL) { // for first n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp1[bs] = max(dp1[bs], dp1[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp1[bs] = cur.size();

		tr(bs)
		tr(dp1[bs])
	}

	for (long long bs = (1LL << mi); bs < (1LL << n); bs += (1LL << mi)) { // for second n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = mi; node < n; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp2[bs] = max(dp2[bs], dp2[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp2[bs] = cur.size();

		tr(bs)
		tr(dp2[bs])
	}

	int ans = 0;

	for (long long bs = 0; bs < (1LL << mi); bs += 1LL) { // meet in the middle
		long long getHalf = ((1LL << (n - mi)) - 1) << mi;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				for (int i = mi; i < n; i++) {
					tr(node)
					tr(i)
					if (adj[node][i]) {
						getHalf &= (~(1LL << i));
					}
				}
			}
		}
		tr(bs)
		tr(getHalf)
		ans = max(ans, dp1[bs] + dp2[getHalf]);
	}

	cout << ans;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cerr << adj[i][j];
		cerr << '\n';
	}

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

int ans, q, m, type; string t;
set<string> names;
vector<pii> v;
int fi[50], la[50];
vector<pii> seg;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> q >> m;
	for (int i = 0; i < q; i++) {
		cin >> type;
		if (type == 1) v.pb({1, -1});
		else {
			cin >> t; names.insert(t);
			v.pb({2, names.size()});
		}
	}

	memset(fi, -1, sizeof(fi));

	for (int i = 0, seen = -1; i < v.size(); i++) {
		if (v[i].fi == 1) seen = i;
		else {
			if (fi[v[i].se] == -1) fi[v[i].se] = seen;
			la[v[i].se] = seen;
		}
	}

	for (int i = 1; i <= m; i++) {
		seg.pb({fi[i], la[i]});
	}

	sort(seg.begin(), seg.end(), [](pii x, pii y) {
		if (x.se != y.se) return x.se < y.se;
		return x.fi < y.fi;
	});

	int ans = 0, cur = -1;

	for (auto x : seg) {
		if (cur < x.fi) cur = x.se, ans++;
	}

	cout << ans;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

bool adj[50][50]; // 0-based
unordered_map<long long, int> dp1, dp2; // meet in the middle
int n;

void buildGraph() {
	int events; cin >> events >> n;
	map<string, int> m;
	vector<int> cur;

	for (int i = 0, type; i < events; i++) {
		cin >> type;
		if (type == 1) {
			for (int x : cur) for (int y : cur) {
				if (x != y) adj[x][y] = 1;
			}
			cur.clear();
		}
		else {
			string name; cin >> name;
			if (!m.count(name)) {
				int k = m.size();
				m[name] = k;
			}
			cur.pb(m[name]);
		}
	}
	for (int x : cur) for (int y : cur) {
		if (x != y) adj[x][y] = adj[y][x] = 1;
	}
	for (auto op : m) {
		cerr << op.fi << ' ' << op.se << '\n';
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	buildGraph();

	int mi = n / 2;

	dp1[0] = dp2[0] = 0;

	for (long long bs = 1; bs < (1LL << mi); bs += 1LL) { // for first n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp1[bs] = max(dp1[bs], dp1[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp1[bs] = cur.size();

		tr(bs)
		tr(dp1[bs])
	}

	for (long long bs = (1LL << mi); bs < (1LL << n); bs += (1LL << mi)) { // for second n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = mi; node < n; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp2[bs] = max(dp2[bs], dp2[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp2[bs] = cur.size();

		tr(bs)
		tr(dp2[bs])
	}

	int ans = 0;

	for (long long bs = 1; bs < (1LL << mi); bs += 1LL) { // meet in the middle
		long long getHalf = ((1LL << (n - mi)) - 1) << mi;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				for (int i = mi; i < n; i++) {
					tr(node)
					tr(i)
					if (adj[node][i]) {
						getHalf &= (~(1LL << i));
					}
				}
			}
		}
		tr(bs)
		tr(getHalf)
		ans = max(ans, dp1[bs] + dp2[getHalf]);
	}

	cout << ans;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cerr << adj[i][j];
		cerr << '\n';
	}

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

bool adj[50][50]; // 0-based
unordered_map<long long, int> dp1, dp2; // meet in the middle
int n;

void buildGraph() {
	int events; cin >> events >> n;
	map<string, int> m;
	vector<int> cur;

	for (int i = 0, type; i < events; i++) {
		cin >> type;
		if (type == 1) {
			for (int x : cur) for (int y : cur) {
				if (x != y) adj[x][y] = 1;
			}
			cur.clear();
		}
		else {
			string name; cin >> name;
			if (!m.count(name)) m[name] = m.size();
			cur.pb(m[name]);
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	buildGraph();

	int mi = n / 2;

	dp1[0] = dp2[0] = 0;

	for (long long bs = 1; bs < (1LL << mi); bs += 1LL) { // for first n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp1[bs] = max(dp1[bs], dp1[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp1[bs] = cur.size();
	}

	for (long long bs = (1LL << mi); bs < (1LL << n); bs += (1LL << mi)) { // for second n/2 nodes, compute max for each bitset
		vector<int> cur;
		for (int node = mi; node < n; node++) {
			if ((1LL << node) & bs) {
				cur.pb(node);
				dp2[bs] = max(dp2[bs], dp2[bs ^ (1LL << node)]);
			}
		}
		bool invalid = 0;
		for (int x : cur) for (int y : cur) if (adj[x][y]) invalid = 1;
		if (not invalid) dp2[bs] = cur.size();
	}

	int ans = 0;

	for (long long bs = 1; bs < (1LL << mi); bs += 1LL) { // meet in the middle
		long long getHalf = ((1LL << (n - mi)) - 1) << mi;
		for (int node = 0; node < mi; node++) {
			if ((1LL << node) & bs) {
				for (int i = mi; i < n; i++) if (adj[node][i]) getHalf &= (~(1LL << i));
			}
		}
		ans = max(ans, dp1[bs] + dp2[getHalf]);
	}

	cout << ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

int ans, q, m, type, cnt; string t;
map<string, int> names;
vector<pii> v;
int adj[50][50];
vector<int> e[50];
long long mask;

void dfs(int v, int cur = 0) {
	if (cur + 1 < ans) return;
	if (v == m + 1) {
		ans = max(ans, __builtin_popcount(mask));
		return;
	}

	int ok = 1;
	for (int u : e[v]) {
		if (mask & (1LL << u)) ok = 0;
	}

	if (ok) {
		mask ^= (1LL << v);
		dfs(v + 1, cur + 1);
		mask ^= (1LL << v);
	}
	dfs(v + 1);
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> q >> m;
	names.clear();
	for (int i = 0; i < q; i++) {
		cin >> type;
		if (type == 1) v.pb({1, -1});
		else {
			cin >> t;
			if (!names.count(t)) names[t] = ++cnt;
			v.pb({2, names[t]});
		}
	}
	v.pb({1, -1}); q++;

	long long bs = 0;
	for (int i = 0; i < q; i++) {
		cerr << v[i].fi << ' ' << v[i].se << '\n';
		if (v[i].fi == 1) {
			for (int x = 1; x <= m; x++) {
				if (bs & (1LL << x)) {
					for (int y = x + 1; y <= m; y++) {
						if (bs & (1LL << y)) adj[x][y] = adj[y][x] = 1;
					}
				}
			}
			bs = 0;
		}
		else bs |= (1LL << v[i].se);
	}

	for (int i = 1; i <= m; i++)
	for (int j = 1; j <= m; j++) if (adj[i][j]) e[i].pb(j);

	dfs(1);

	cout << ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define DEBUG 0
#define cerr if (DEBUG) cerr
#define fprintf if (DEBUG) fprintf
#define local freopen("in.txt","r",stdin);
#define test cerr<<"hi\n";
#define tr(x) cerr<<#x" "<<x<<'\n';
#define fi first
#define se second
#define HH1 402653189
#define HH2 1610612741
#define INF 0x3f3f3f3f
#define tii tuple<int,int,int>
#define npos string::npos

using namespace std;

#define MOD 1000000007LL

int ans, q, m, type; string t;
set<string> names;
vector<pii> v;
int fi[50], la[50];
vector<pii> seg;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> q >> m;
	for (int i = 0; i < q; i++) {
		cin >> type;
		if (type == 1) v.pb({1, -1});
		else {
			cin >> t; names.insert(t);
			v.pb({2, names.size()});
		}
	}

	memset(fi, -1, sizeof(fi));

	for (int i = 0, seen = -1; i < v.size(); i++) {
		if (v[i].fi == 1) seen = i;
		else {
			if (fi[v[i].se] == -1) fi[v[i].se] = seen;
			la[v[i].se] = seen;
		}
	}

	for (int i = 1; i <= m; i++) {
		seg.pb({fi[i], la[i]});
	}

	sort(seg.begin(), seg.end(), [](pii x, pii y) {
		if (x.fi != y.fi) return x.fi < y.fi;
		return x.se > y.se;
	});

	int ans = 0, cur = -1;

	for (auto x : seg) {
		if (cur < x.fi) cur = x.se, ans++;
	}

	cout << ans;

}