#include using ll = long long; using std::cin; using std::cout; using std::endl; std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); template inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr int inf = (int)1e9 + 7; constexpr long long INF = 1LL << 60; void solve() { int n, m; cin >> n >> m; std::vector a(m); for (int i = 0; i < m; i++) { cin >> a[i]; } std::vector T(n, std::vector(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> T[i][j]; } } std::vector res(n, -1); std::vector cnt(m, 0); for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { if (res[i] != -1) continue; if (cnt[T[i][j]] < a[T[i][j]]) { res[i] = T[i][j]; cnt[T[i][j]]++; } } } for (int i = 0; i < n; i++) { cout << res[i] << " \n"[i == n - 1]; } } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int kkt = 1; // cin >> kkt; while (kkt--) { solve(); } }