#include #include #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace std; using namespace atcoder; typedef long long ll; int main() { int n, m; cin >> n >> m; vector a(m); rep(i, 0, m) cin >> a[i]; vector> t(n, vector(m)); rep(i, 0, n) rep(j, 0, m) cin >> t[i][j]; vector ans(n, -1); rep(j, 0, m) { set tmp; rep(i, 0, n) { if (ans[i] == -1) { a[t[i][j]]--; ans[i] = t[i][j]; tmp.insert(-i); } } for (auto x : tmp) { x *= -1; if (a[t[x][j]] < 0) { ans[x] = -1; a[t[x][j]]++; } } } rep(i, 0, n) cout << ans[i] << ' '; }