#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
const int MAXN = 1005;
const int MAXM = 505;
bool G[MAXN][MAXM], used[MAXM];
int M, N;
struct Link
{///标记与y相连的边
int len, link[MAXN];
}Ly[MAXN];
bool Find(int i, int Mid)
{
for(int j=0; j<M; j++)
{
if(G[i][j] && !used[j])
{
used[j] = true;
if( Ly[j].len < Mid )
{
Ly[j].link[ Ly[j].len++ ] = i;
return true;
}
for( int k=0; k<Ly[j].len; k++ )
{
if( Find( Ly[j].link[k], Mid ) == true )
{
Ly[j].link[k] = i;
return true;
}
}
}
}
return false;
}
bool XYL(int Mid)
{///匈牙利的缩写....
memset(Ly, false, sizeof(Ly));
for(int i=0; i<N; i++)
{
memset(used, false, sizeof(used));
if( Find(i, Mid) == false )
return false;
}
return true;
}
int main()
{
while(scanf("%d%d", &N, &M)!= EOF && M+N)
{
int i, v;
char ch, s[100];
memset(G, false, sizeof(G));///记得初始化
for(i=0; i<N; i++)
{
scanf("%s", s);
while(scanf("%d%c", &v, &ch))
{
G[i][v] = true;
if( ch == ‘\n‘ )
break;///不能输入的时候终止
}
}
int L = 0, R = N, ans=N;
while(L <= R)
{
int Mid = (L+R)>>1;
if( XYL(Mid) == true )
{
ans = Mid;
R = Mid - 1;
}
else
L = Mid + 1;
}
printf("%d\n", ans);
}
return 0;
}