#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 5e3+10;
int map[110][110];
int match[N], st[N];
int n, m, k;
bool dfs(int x)
{
for (int i = 1;i <= m;i++)
{
if (map[x][i] && st[i] == 0)
{
st[i] = 1;
if (match[i] == -1 || dfs(match[i]))
{
match[i] = x;
return true;
}
}
}
return false;
}
int Solve()
{
memset(match, -1, sizeof(match));
int cnt = 0;
for (int i = 1;i <= n;i++)
{
memset(st, 0, sizeof(st));
if (dfs(i))
cnt++;
}
return cnt;
}
int main()
{
while (~scanf("%d", &n) && n)
{
scanf("%d", &m);
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
scanf("%d", &map[i][j]);
int cnt = Solve();
printf("%d
", cnt);
}
return 0;
}