#include using namespace std; typedef long long ll; typedef pair P; typedef pair Q; #define REP(i,n) for(int i=0;i> N >> M; REP(i,M) cin >> A[i]; REP(i,N) REP(j,M) cin >> T[i][j]; vector v(N,-1); REP(j,M) REP(i,N){ if(v[i]!=-1) continue; int x=T[i][j]; if(A[x]==0) continue; v[i]=x; A[x]--; } REP(i,N) cout << v[i] << ' '; cout << endl; return 0; }