#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n, m; cin >> n >> m; vector a(m); rep(i, m) cin >> a[i]; vector t(n, vector(m)); rep(i, n) rep(j, m) cin >> t[i][j]; vector ans(n, -1); queue q; rep(i, n) q.push(i); rep(j, m) { queue nxtq; while (!q.empty()) { int i = q.front(); q.pop(); assert(ans[i] == -1); if (a[t[i][j]] == 0) { nxtq.push(i); continue; } ans[i] = t[i][j]; a[t[i][j]]--; } swap(q, nxtq); } rep(i, n) cout << ans[i] << " "; cout << endl; return 0; }