/*
    Author: Loc Thien Vo
    From: Ben Tre, Viet Nam
    Organization: Ben Tre High School for Gifted Students (HSGS Ben Tre) | M-IT_CBT_23-26
*/

#include<bits/stdc++.h>
using namespace std;

#define    NAME                "message"
#define    FastIO              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void setData() {
    FastIO
    if(fopen(NAME ".INP", "r")) {
        freopen(NAME ".INP", "r", stdin);
        freopen(NAME ".OUT", "w", stdout);
    }
}

/*
    My Solution: Dynamic Programming
*/

const int        N              = (int)5e2 + 5;
const int        M              = (int)5e2 + 5;
const int        INT_INF        = (int)1e9 + 7;
const long long  LL_INF         = (long long)1e18 + 7;
const int        MOD[3]         = {(int)1e9 + 7, (int)1e9 + 2277, (int)1e9 + 5277};

int numPack, numChannel;
long long cost[N][M];

long long F[N][M]; // F[i][j]: Chi phi chuyen i goi tin dau tien tren j mang dau tien
int tr[N][M]; // tr[i][j]: So goi dung tren kenh j de chuyen duoc i goi tin dau tien

int res[M]; // res[j]: So goi dung tren kenh j trong cach chuyen toi uu nhat (dap an bai toan)

void read() {
    cin >> numPack >> numChannel;
    for(int i = 1; i <= numPack; ++i)
		for(int j = 1; j <= numChannel; ++j) cin >> cost[i][j];
}

long long dp() {
    // BTCS
    for(int i = 0; i <= numPack; ++i) F[i][0] = 0LL;
    for(int j = 0; j <= numChannel; ++j) F[0][j] = 0LL;
    for(int i = 1; i <= numPack; ++i) F[i][1] = cost[i][1], tr[i][1] = i;

    // CTTH
    for(int i = 1; i <= numPack; ++i) {
		for(int j = 2; j <= numChannel; ++j) {
	        // Truong hop khong chon kenh j de chuyen bat ki goi tin nao
	        F[i][j] = F[i][j - 1];
	        tr[i][j] = 0;
	
	        // Truong hop chuyen k = {1, 2, ... i} goi tin tren kenh j
	        long long best = LL_INF;
	        int packNeeded = 0;
	        for(int k = 1; k <= i; ++k) if(F[i - k][j - 1] + cost[k][j] < best) {
	            best = F[i - k][j - 1] + cost[k][j];
	            packNeeded = k;
	        }
	
	        // Tim min cua ca 2 truong hop
	        if(best < F[i][j - 1]) F[i][j] = best, tr[i][j] = packNeeded;
		}
    }

    // Nghiem
    return F[numPack][numChannel];
}

void trace() {
    int packRemain = numPack;

    for(int j = numChannel; j >= 1; --j) {
        res[j] = tr[packRemain][j];
        packRemain -= tr[packRemain][j];
    }

	for(int j = 1; j <= numChannel; ++j) cout << res[j] << "\n";
}

void solve() {
    cout << dp() << "\n";
    trace();
}

int main() {
    setData();
    read(); solve();

    return 0;
}