#include #include using namespace std; int main() { int n, m; cin >> n >> m; vector a(m); for (int i = 0; i < m; i++) cin >> a[i]; vector room(m); vector t(n, vector(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> t[i][j]; } vector ans(n, -1); for (int k = 0; k < m; k++) { for (int i = 0; i < n; i++) { if (ans[i] == -1) { if (room[t[i][k]] < a[t[i][k]]) { room[t[i][k]]++; ans[i] = t[i][k]; } } } } for (int i = 0; i < n; i++) { if (i > 0) cout << ' '; cout << ans[i]; } cout << "\n"; }