#include #include #include using namespace std; int main(){ int h, w; cin >> h >> w; vector s(h); for(auto &it: s) cin >> it; string ans = ""; int i = 0, j = 0; while(true){ ans += s[i][j]; if(i == h-1 && j == w-1) break; if(i+1 < h && j+1 < w){ if(s[i+1][j] < s[i][j+1]) i++; else j++; }else if(i+1 < h) i++; else j++; } cout << ans << endl; return 0; }