extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::fmt::{Display, Error, Formatter, Binary};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet};

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
fn min_path(hotels: &Vec<Vec<i32>>, day: usize, prev: usize, memo: &mut Vec<Vec<i32>>) -> i32 {
    if day == hotels[0].len() {
        0
    }else if memo[prev % hotels.len()][day] >= 0 {
        memo[prev % hotels.len()][day]
    }else {
        let mut r = std::i32::MAX;
        let mut min_cost = std::i32::MAX;
        for i in 0 .. hotels.len() {
            min_cost = min(min_cost, hotels[i][day]);
        }
        for i in 0 .. hotels.len() {
            if hotels[i][day] == min_cost {
                r = min(r, min_path(hotels, day + 1, i, memo) + if i == prev {0} else {1});
            }
        }
        memo[prev % hotels.len()][day] = r;
        r
    }
}
fn make_min_path(hotels: &Vec<Vec<i32>>) -> (i32, i32, Vec<usize>){
    let mut prev = hotels.len();
    let mut result = Vec::with_capacity(hotels[0].len());
    let mut min_path_memo = vec![vec![-1; hotels[0].len()]; hotels.len()];
    let mut min_length_of_whole = 0;
    let mut min_cost_of_whole = 0;
    for day in 0 .. hotels[0].len() {
        let mut min_cost = std::i32::MAX;
        for j in 0 .. hotels.len() {
            min_cost = min(min_cost, hotels[j][day]);
        }
        let mut min_length = std::i32::MAX;
        for j in 0 .. hotels.len() {
            if min_cost == hotels[j][day] {
                min_length = min(min_length, min_path(hotels, day + 1, j, &mut min_path_memo) + if prev != hotels
                    .len() && prev != j {1}else {0});
            }
        }
        if day == 0 {
            min_length_of_whole = min_length;
        }
        min_cost_of_whole += min_cost;
        for j in 0 .. hotels.len() {
            if min_cost == hotels[j][day] && min_length == min_path(hotels, day + 1, j, &mut min_path_memo) + if prev != hotels
                .len() && prev != j {1}else {0} {
                result.push(j);
                prev = j;
                break
            }
        }
    }
    (min_cost_of_whole, min_length_of_whole, result)
}
fn main() {
    let_all!(n: usize, d: usize);
    let mut hotels = Vec::with_capacity(n);
    for _ in 0 .. n {
        hotels.push(read_line!(' '; i32));
    }
    match make_min_path(&hotels) {
        (cost, length, path) => {
            println!("{} {}", cost, length);
            for p in path {
                println!("{}", p + 1);
            }
        }
    }
}


Measured memory_bytes: 5056