#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector S(N),T(M); for(auto &s : S) cin >> s; for(auto &t : T) cin >> t; vector> OK(N+1,vector(M+1)); OK.at(N).at(M) = true; for(int i=N-1; i>=0; i--){ OK.at(i) = OK.at(i+1); for(int k=0; k best(N-M,1001001),now(N-M); auto dfs = [&](auto dfs,int pos,int p) -> void { if(pos == N){ best = min(best,now); return; } if(OK.at(pos).at(p) == false) return; if(p == M) now.at(pos-p) = S.at(pos),dfs(dfs,pos+1,p); else{ if(S.at(pos) == T.at(p)) dfs(dfs,pos+1,p+1); if(pos-p < N-M) now.at(pos-p) = S.at(pos),dfs(dfs,pos+1,p); } }; dfs(dfs,0,0); for(auto &a : best) cout << a << " "; cout << endl; }