#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } template ostream& operator << (ostream& os, const vector& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w, v; cin >> h >> w; vector ans(h, -1), cnt(w); vector> A(h, vector(w)); cin >> cnt >> A; for(int x = 0; x < w; x++){ for(int y = 0; y < h; y++){ if(ans[y] == -1 && cnt[A[y][x]] >= 1){ cnt[A[y][x]]--; ans[y] = A[y][x]; } } } cout << ans << '\n'; }