#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,m; cin >> n >> m; vector A(m); for (auto& a: A) cin >> a; vector> T; for (int i = 0; i < n; i++){ vector t(m); for (auto& a: t) cin >> a; T.push_back(t); } vector ans(n,-1); for (int i = 0; i < m; i++){ for (int j = 0; j < n; j++){ if (ans[j] != -1) continue; int t = T[j][i]; if (A[t]){ ans[j] = t; A[t]--; } } } for (auto a: ans){ cout << a << " "; } cout << endl; return 0; }