#include using namespace std; using ll = long long; #define rep(i, n) for(int i = 0; i < n; i++) 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); int k = 0; while(1) { vector> g(M); rep(i, N) { if(ans[i] >= 0) continue; g[t[i][k]].push_back(i); } rep(i, M) { int sz = g[i].size(); sz = min(sz, a[i]); rep(j, sz) { int k = g[i][j]; ans[k] = i; a[i]--; } } int f = 0; rep(i, N) { if(ans[i] < 0) { f = 1; break; } } if(f == 0) break; k++; } rep(i, N) cout << ans[i] << " "; cout << endl; }