#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,inline,unroll-loops")
#define rep(a,b,c) for(ll a=b;a<=c;++a)
#define per(a,b,c) for(ll a=b;a>=c;--a)
#define ll long long
#define ff first
#define ss second
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll N=2005,inf=1e18;
ll Ceil(ll a,ll b){return (a+b-1)/b;}
ll n,L,V[N][N],P[N],tar[N],A[N],cnt[N];
bool check(){
fill(cnt+1,cnt+L+1,n);
ll ptr=1;
rep(i,1,n){
ll cur=0,u=P[i],d=0;
while(cur<tar[u]){
if(ptr>L) return false;
if(cur+V[u][ptr]*cnt[ptr]<tar[u]) cur+=V[u][ptr]*cnt[ptr],d+=cnt[ptr],cnt[ptr]=0,ptr++;
else{
ll c=Ceil(tar[u]-cur,V[u][ptr]);
cur+=V[u][ptr]*c;
cnt[ptr]-=c;
d+=c;
if(cnt[ptr]==0) ptr++;
}
}
A[i]=A[i-1]+d;
}
return true;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>n>>L;
rep(i,1,n) rep(j,1,L) cin>>V[i][j],tar[i]+=V[i][j];
iota(P+1,P+n+1,1);
while(true){
if(check()){
rep(i,1,n-1) cout<<A[i]<<' '<<n<<'\n';
rep(i,1,n) cout<<P[i]<<' ';
cout<<'\n';
return 0;
}
if(!next_permutation(P+1,P+n+1)) break;
}
cout<<-1<<'\n';
return 0;
}