#include #include #include #include #include #include #include using namespace std; typedef pair> P; int main() { int N, M; cin >> N >> M; vector A(M); for (int &a: A) cin >> a; auto compare = [](P a, P b) { if (a.second.size() != b.second.size()) return a.second.size() < b.second.size(); return a.first > b.first; }; priority_queue, decltype(compare)> que {compare}; for (int i = 0; i < N; i++) { deque h; for (int j = 0; j < M; j++) { int T; cin >> T; h.push_back(T); } que.push(make_pair(i, h)); } map mp; vector ans(N); while (!que.empty()) { P nxt = que.top(); que.pop(); int h = nxt.second.front(); nxt.second.pop_front(); if (mp[h] < A[h]) { mp[h]++; ans[nxt.first] = h; } else { que.push(make_pair(nxt.first, nxt.second)); } } for (int i = 0; i < N; i++) { cout << ans[i] << (i + 1 == N? '\n': ' '); } return 0; }