bool find(int a)
{
        
for(int i=1;i<=m;i++)
        {
                
if(g[a][ i ]==1&&!b[ i ])
                {
                        b[ i ]
=true;
                        
if(link[ i ]==0||find(link[ i ]))
                        {
                                link[ i ]
=a;
                                
return true;
                        }
                }
        }
        
return false;
}

int main()
{
        
while(init())
        {
                
for(int i=1;i<=n;i++)
                {
                        memset(b,
0,sizeof(b));
                        
if(find(i))ans++;
                }
                printf(
"%d\n",ans);
        }
}