#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#define MAXR 10
#define MAXC 100
using namespace std;
int main()
{
int m,n;//row column
int array[MAXR][MAXC],mini[MAXR][MAXC],child[MAXR][MAXC];//entry,minimum sum, path
while(cin>>m>>n){if(feof(stdin))break;
int i,j;//iterator
for(i=0;i<m;i++)
for(j=0;j<n;j++)cin>>array[i][j]; //array entry
for(i=0;i<m;i++){mini[i][n-1]=array[i][n-1];}
for(j=n-2;j>=0;j--) //dp apply +child set
for(i=0;i<m;i++)
{
mini[i][j]=mini[(m+i-1)%m][j+1];
child[i][j]=(m+i-1)%m;
if(mini[i][j]>mini[i][j+1]){mini[i][j]=mini[i][j+1];
child[i][j]=i;
}
else if(mini[i][j]==mini[i][j+1] && child[i][j]>i)child[i][j]=i;
if(mini[i][j]>mini[(m+i+1)%m][j+1])
{mini[i][j]=mini[(m+i+1)%m][j+1];
child[i][j]=(m+i+1)%m;
}
else if(mini[i][j]==mini[(m+i+1)%m][j+1] && child[i][j]>(m+i+1)%m)
child[i][j]=(m+i+1)%m;
mini[i][j]+=array[i][j];
}
int minimum=30000000,minirow;
for(i=0;i<m;i++)if(minimum>mini[i][0]){minimum=mini[i][0];
minirow=i;
} //minimum sum and source find
vector<int>path;
bool blank =false;
for(j=0;j<n;j++){path.push_back(minirow+1); //path ready+print
if(blank)cout<<" ";
cout<<path[j];
minirow=child[minirow][j];
blank=true;
}
cout<<endl;
cout<<minimum<<endl;
}
return 0;
}