#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(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> B(M); vector fix(N, false); vector done(M, false); rep(k, N) { rep(j, N) { if (fix[j]) continue; if (done[T[j][k]]) continue; B[T[j][k]].push_back(j); fix[j] = true; } rep(i, M) { if (done[i]) continue; while ((int)B[i].size() > A[i]) { fix[B[i][(int)B[i].size() - 1]] = false; B[i].pop_back(); } if ((int)B[i].size() == A[i]) done[i] = true; } } vector C(N); rep(i, M) { for (int j : B[i]) C[j] = i; } rep(i, N) cout << C[i] << " "; cout << endl; return 0; }