/*裸地KM*/ #include<iostream> #include<cstdio> #include<cstring> #define maxn 110 #define inf 0x3f3f3f3f using namespace std; int n,m,ans,match[maxn],w[maxn][maxn],d; int fx[maxn],fy[maxn],lx[maxn],ly[maxn]; bool Dfs(int i) {fx[i]=1;for(int j=1;j<=m;j++)if(fy[j]==0&&lx[i]+ly[j]==w[i][j]){fy[j]=1;if(match[j]==0||Dfs(match[j])){match[j]=i;return 1;}}return 0; } void KM() {for(int i=1;i<=n;i++){lx[i]=-inf;for(int j=1;j<=m;j++)lx[i]=max(lx[i],w[i][j]);}for(int i=1;i<=n;i++){while(1){memset(fx,0,sizeof(fx));memset(fy,0,sizeof(fy));if(Dfs(i))break;d=inf;for(int j=1;j<=n;j++)for(int k=1;k<=m;k++)if(fx[j]&&!fy[k])d=min(d,lx[j]+ly[k]-w[j][k]);if(d==inf)break;for(int j=1;j<=n;j++)if(fx[j])lx[j]-=d;for(int j=1;j<=m;j++)if(fy[j])ly[j]+=d;}}for(int i=1;i<=m;i++)if(match[i])ans+=w[match[i]][i]; } int main() {scanf("%d%d",&n,&m);for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&w[i][j]);KM();printf("%d\n",ans);return 0; }