#include #include #define pub push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (ll i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (ll i = int(b) - 1; i >= int(a); i--) #define all(c) (c).begin(), (c).end() using namespace std; using namespace atcoder; using ll = long long; using dd = double; using Pll = pair; using vll = vector< ll>; using vdd = vector< dd>; using vvll = vector< vll>; using vvdd = vector; using vvvll = vector< vvll>; using vvvdd = vector; using vvvvll = vector; using vchar = vector< char>; using vvchar = vector; using mint = modint998244353; using mint2 = modint1000000007; using vmint = vector< mint>; using vmint2 = vector< mint2>; using vvmint = vector; using vvmint2 = vector; constexpr long long INF = (1LL << 60); constexpr double EPS = 1e-9; constexpr double PI = 3.141592653589; ////////////////////////////////////////////////////////// template bool chmax(T& a, const T& b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template bool chmin(T& a, const T& b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } string zfill(int n, const int width) { stringstream ss; ss << setw(width) << setfill('0') << n; return ss.str(); } //1+2+3+…+N ll OnetoN_sum(ll N) { return (N * (N + 1)) / 2; } template void outvec(vector A) { ll N = A.size(); rep(i, N) { cout << A[i] << " "; } cout << endl; return; } ll max(int x, ll y) { return max((ll)x, y); } ll max(ll x, int y) { return max(x, (ll)y); } int min(int x, ll y) { return min((ll)x, y); } int min(ll x, int y) { return min(x, (ll)y); } template std::map factorize(T n) { std::map factor_map; for (T i = 2; i * i <= n; i++) { while (!(n % i)) { factor_map[i]++; n /= i; } } if (n > 1) factor_map[n]++; return factor_map; } template vector divisor(T n) { vector ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); // 昇順に並べる return ret; } template bool isp(T num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } template vector Era(ll N) { vector isprime(N + 1, true); isprime[0] = isprime[1] = false; for (ll p = 2; p <= N; ++p) { if (!isprime[p]) continue; for (ll q = p * 2; q <= N; q += p) { isprime[q] = false; } } return isprime; } ll LIS(const std::vector& v) { std::vector dp; for (const auto& elem : v) { auto it = std::lower_bound(dp.begin(), dp.end(), elem); if (it == dp.end()) { dp.push_back(elem); } else { *it = elem; } } return dp.size(); } ///////////////////////////////////////////////////// //op:二項演算 e:単位元 //range max query ll op(ll a, ll b) { return max(a, b); } ll e() { return -INF; } int main() { //cout << fixed << setprecision(10); ios::sync_with_stdio(false); cin.tie(nullptr); ll N, M; cin >> N >> M; vvll A(N, vll(N)); rep(i, N) { rep(j, N) { cin >> A[i][j]; } } vector> B(M); vector> C(M); vector> ans(M,vll(N)); rep(i, M) { rep(j, N) { B[i].insert(j + 1); C[i].insert(j + 1); } } rep(i, N) { rep(j, N) { rep(k, A[i][j]) { bool ok = false; rep(l, M) { if (B[l].count(j + 1) && C[l].count(i + 1)) { B[l].erase(j + 1); C[l].erase(i + 1); ans[l][i] = j + 1; ok = true; break; } } if (!ok) { cout << -1 << endl; return 0; } } } } rep(i, M) { rep(j, N) { cout << ans[i][j] << " "; } cout << endl; } }