#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; using pii=pair; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int h,w; cin>>h>>w; vector S(h); rep(i,h) cin>>S[i]; vector ans(h+w-1); ans[0]=S[0][0]; set se; se.insert({0,0}); for(int k=1;k=w) continue; bool b=false; if(i>0 && se.count({i-1,j})) b=true; if(j>0 && se.count({i,j-1})) b=true; if(b==false) continue; tmp=min(tmp,S[i][j]); } ans[k]=tmp; set se2; rep(i,h){ int j=k-i; if(j<0 || j>=w) continue; if(S[i][j]!=tmp) continue; bool b=false; if(i>0 && se.count({i-1,j})) b=true; if(j>0 && se.count({i,j-1})) b=true; if(b==false) continue; se2.insert({i,j}); } swap(se,se2); } rep(i,h+w-1) cout<