/**
    F11 COMPETITION
    Problema: Cutii n-dimensionale
    Runda: 1
    Echipa: Quicksilver
**/

#include <algorithm>
#include <cmath>
#include <cstring>
#include <fstream>
#include <vector>
using namespace std;

#define INPUT "cutii.in"
#define OUTPUT "cutii.out"
#define MAX_DIM 21

int sol, solIndex, nBoxes, nDim;
int ind[MAX_DIM], best[MAX_DIM], prev[MAX_DIM];
vector<int> boxes[MAX_DIM];

/** READ **/
void read() {
    ifstream fin(INPUT);
    fin >> nBoxes;
    fin >> nDim;
    for (int i = 0; i < nBoxes; ++i) {
        ind[i] = i;
        boxes[i].resize(nDim);
        for (int j = 0; j < nDim; ++j)
            fin >> boxes[i][j];
    }
    fin.close();
}

/** SOLVE **/
bool fit(int firstBoxIndex, int secondBoxIndex) {
    for (int i = 0; i < nDim; ++i)
        if (boxes[firstBoxIndex][i] > boxes[secondBoxIndex][i])
            return 0;
    return 1;
}

double compLogVol(int index) {
    double logVol = 0;
    for (int i = 0; i < nDim; ++i)
        logVol += log10(boxes[index][i]);
    return logVol;
}

void sortDim() {
    for (int i = 0; i < nBoxes; ++i)
        sort(boxes[i].begin(), boxes[i].end());
}

void sortIndByVol() {
    for (int i = 0; i < nBoxes - 1; ++i)
        for (int j = i + 1; j < nBoxes; ++j)
            if (compLogVol(ind[i]) > compLogVol(ind[j]))
                swap(ind[i], ind[j]);
}

void solve() {
    sortDim();
    sortIndByVol();
    for (int i = 0; i < nBoxes; ++i) {
        best[i] = 1;
        prev[i] = -1;
        for (int j = 0; j < i; ++j)
            if (fit(ind[j], ind[i]) && best[j] + 1 > best[i]) {
                best[i] = best[j] + 1;
                prev[i] = j;
            }
        if (best[i] > sol) {
            sol = best[i];
            solIndex = i;
        }
    }
}

/** PRINT **/
ofstream fout(OUTPUT);

void printSolInd(int index) {
    if (index == -1)
        return;
    printSolInd(prev[index]);
    fout << ind[index] + 1 << " ";
}

void print() {
    fout << sol << "\n";
    printSolInd(solIndex);
    fout.close();
}

/** MAIN **/
int main() {
    read();
    solve();
    print();
    return 0;
}
