#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int H,W; cin>>H>>W; vector S(H); rep(i,H)cin>>S[i]; string ans = string(1,S[0][0]); vector> x(1,make_pair(0,0)); rep(i,H+W-2){ vector> nx; char c = 'z'; rep(j,x.size()){ rep(k,2){ int xx = x[j].first,yy = x[j].second; if(k==0)xx++; else yy++; if(xx>=H||xx<0||yy>=W||yy<0)continue; c = min(c,S[xx][yy]); } } ans += c; rep(j,x.size()){ rep(k,2){ int xx = x[j].first,yy = x[j].second; if(k==0)xx++; else yy++; if(xx>=H||xx<0||yy>=W||yy<0)continue; if(S[xx][yy]==c){ nx.emplace_back(xx,yy); } } } sort(nx.begin(),nx.end()); nx.erase(unique(nx.begin(),nx.end()),nx.end()); x = nx; } cout<