#include using namespace std; int main() { int N, M; cin >> N >> M; vector A(M), Cap(M), Ans(N); for (int &a : A) cin >> a; vector Stu(N); vector T(N, vector(M)); priority_queue, vector>, greater>> PQ; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> T.at(i).at(j); T.at(i).at(j) += j * 1000; PQ.push({T.at(i).at(j), i}); } } while(!PQ.empty()) { pair P = PQ.top(); PQ.pop(); if (Stu.at(P.second) || (Cap.at(P.first % 1000) == A.at(P.first % 1000))) continue; Ans.at(P.second) = P.first % 1000; Stu.at(P.second) = true; Cap.at(P.first % 1000)++; } for (int i = 0; i < N; i++) cout << Ans.at(i) << (i != N - 1 ? ' ' : '\n'); }