#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
using namespace std;
const int MAX=3e5+5;
const int LOG=20;
const int MAXL=(1<<LOG)+5;
const int INF=1<<30;
int N,M,T;
int A[MAX];
pii dp[MAXL];
pii mrg(pii a,pii b){
pii c;
c.first=max(a.first,b.first);
c.second=(c.first==a.first?max(b.first,a.second):max(a.first,b.second));
return c;
}
int C[LOG];
int main(){
cin>>N>>M;T=N/2;
for (int i=0;i<N;i++) for (int j=0;j<M;j++){
int a;cin>>a;
A[i]+=a<<j;
}
fill_n(dp,1<<M,make_pair(-INF,-INF));
for (int i=0;i<N;i++){
int a=(1<<M)-1-A[i];
if (dp[a].first==0) dp[a].second=0;
else dp[a].first=0;
}
for (int k=0;k<M;k++) for (int bm=0;bm<1<<M;bm++){
if (bm&(1<<k)) continue;
int a=bm,b=bm^(1<<k);
auto p=dp[a],q=dp[b];
dp[a]=mrg(p,q);
q.first++,q.second++;
dp[b]=mrg(p,q);
}
for (int i=0;i<N;i++) for (int k=0;k<M;k++) if (A[i]&(1<<k)) C[k]++;
for (int i=0;i<N;i++){
int ans=0;
int t=0;
for (int k=0;k<M;k++){
int c=C[k];
if (A[i]&(1<<k)) c--;
if (c>T) ans++;
else if (c==T) t+=1<<k;
}
int a=0;
for (int k=0;k<M;k++) if ((t&(1<<k))&&!(A[i]&(1<<k))) a++;
auto [p0,p1]=dp[t];
if (p0==a) ans+=p1;
else ans+=p0;
cout<<ans<<'\n';
}
}