#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) void solve() { ll n, m; cin >> n >> m; vector a(m), c(m, 0), ans(n, -1); rep(i, m) cin >> a[i]; vector t(n, vector(m)); rep(j, n) rep(k, m) cin >> t[j][k]; rep(k, m) rep(j, n) { ll x = t[j][k]; if (ans[j] == -1 && c[x] < a[x]) c[x]++, ans[j] = x; } rep(i, n) cout << (i ? " " : "") << ans[i]; cout << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }