//84104971101048411497 - Can you guess what does this mean?
using namespace std;
#include <bits/stdc++.h>
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define fordit(rit, type, var) for(type::reverse_iterator rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define maxN 15
#define maxK 35
struct box {
int id, n;
int d[maxN];
inline bool operator < (const box &b) const {
fto(i, 1, n)
if (d[i] >= b.d[i]) return false;
return true;
}
};
int k, n, f[maxK], trace[maxK];
box a[maxK];
vector<int> ans;
int main () {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
while (scanf("%d%d", &k, &n) != EOF) {
fto(i, 1, k)
fto(j, 1, n) scanf("%d", &a[i].d[j]);
fto(i, 1, k) {
a[i].id = i;
a[i].n = n;
sort(a[i].d+1, a[i].d+n+1);
}
// Good-old Bubble Sort algorithm
fto(i, 1, k-1)
fto(j, i+1, k)
if (a[j] < a[i]) swap(a[i], a[j]);
// Printing out all boxes
fto(i, 1, k) {
printf("%d\n", a[i].id);
fto(j, 1, n) printf("%d ", a[i].d[j]);
printf("\n");
}
fto(i, 1, k) {
f[i] = 1;
trace[i] = 0;
fto(j, 1, i-1) {
if (a[j] < a[i] && f[i] < f[j]+1) {
f[i] = f[j]+1;
trace[i] = j;
}
}
}
printf("%d\n", *max_element(f+1, f+k+1));
int pos = max_element(f+1, f+k+1)-f;
ans.clear();
int u = pos;
while (trace[u] != 0) {
u = trace[u];
ans.pb(a[u].id);
}
fordit(rit, vector<int>, ans) printf("%d ", *rit);
printf("%d\n", a[pos].id);
}
return 0;
}
Ly84NDEwNDk3MTEwMTA0ODQxMTQ5NyAtIENhb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sKICAgIH0KfTsKCmludCBrLCBuLCBmW21heEtdLCB0cmFjZVttYXhLXTsKYm94IGFbbWF4S107CnZlY3RvcjxpbnQ+IGFuczsKCmludCBtYWluICgpIHsKICAgICNpZm5kZWYgT05MSU5FX0pVREdFCiAgICAgICAgZnJlb3BlbigiaW5wdXQudHh0IiwgInIiLCBzdGRpbik7CiAgICAgICAgLy9mcmVvcGVuKCJvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpOwogICAgI2VuZGlmIC8vIE9OTElORV9KVURHRQoKICAgIHdoaWxlIChzY2FuZigiJWQlZCIsICZrLCAmbikgIT0gRU9GKSB7CiAgICAgICAgZnRvKGksIDEsIGspCiAgICAgICAgICAgIGZ0byhqLCAxLCBuKSBzY2FuZigiJWQiLCAmYVtpXS5kW2pdKTsKICAgICAgICBmdG8oaSwgMSwgaykgewogICAgICAgICAgICBhW2ldLmlkID0gaTsKICAgICAgICAgICAgYVtpXS5uID0gbjsKICAgICAgICAgICAgc29ydChhW2ldLmQrMSwgYVtpXS5kK24rMSk7CiAgICAgICAgfQogICAgICAgIC8vIEdvb2Qtb2xkIEJ1YmJsZSBTb3J0IGFsZ29yaXRobQogICAgICAgIGZ0byhpLCAxLCBrLTEpCiAgICAgICAgICAgIGZ0byhqLCBpKzEsIGspCiAgICAgICAgICAgICAgICBpZiAoYVtqXSA8IGFbaV0pIHN3YXAoYVtpXSwgYVtqXSk7CiAgICAgICAgLy8gUHJpbnRpbmcgb3V0IGFsbCBib3hlcwogICAgICAgIGZ0byhpLCAxLCBrKSB7CiAgICAgICAgICAgIHByaW50ZigiJWRcbiIsIGFbaV0uaWQpOwogICAgICAgICAgICBmdG8oaiwgMSwgbikgcHJpbnRmKCIlZCAiLCBhW2ldLmRbal0pOwogICAgICAgICAgICBwcmludGYoIlxuIik7CiAgICAgICAgfQogICAgICAgIGZ0byhpLCAxLCBrKSB7CiAgICAgICAgICAgIGZbaV0gPSAxOwogICAgICAgICAgICB0cmFjZVtpXSA9IDA7CiAgICAgICAgICAgIGZ0byhqLCAxLCBpLTEpIHsKICAgICAgICAgICAgICAgIGlmIChhW2pdIDwgYVtpXSAmJiBmW2ldIDwgZltqXSsxKSB7CiAgICAgICAgICAgICAgICAgICAgZltpXSA9IGZbal0rMTsKICAgICAgICAgICAgICAgICAgICB0cmFjZVtpXSA9IGo7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcHJpbnRmKCIlZFxuIiwgKm1heF9lbGVtZW50KGYrMSwgZitrKzEpKTsKICAgICAgICBpbnQgcG9zID0gbWF4X2VsZW1lbnQoZisxLCBmK2srMSktZjsKCiAgICAgICAgYW5zLmNsZWFyKCk7CiAgICAgICAgaW50IHUgPSBwb3M7CiAgICAgICAgd2hpbGUgKHRyYWNlW3VdICE9IDApIHsKICAgICAgICAgICAgdSA9IHRyYWNlW3VdOwogICAgICAgICAgICBhbnMucGIoYVt1XS5pZCk7CiAgICAgICAgfQogICAgICAgIGZvcmRpdChyaXQsIHZlY3RvcjxpbnQ+LCBhbnMpIHByaW50ZigiJWQgIiwgKnJpdCk7CiAgICAgICAgcHJpbnRmKCIlZFxuIiwgYVtwb3NdLmlkKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=