#include using namespace std; inline void min_self(long long &a, long long b) { if (b < a) { a = b; } } int main() { iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0); int h, w; cin >> h >> w; vector grid(h); for (int i = 0; i < h; i++) { cin >> grid[i]; } using P = pair>; priority_queue, greater

> que; auto Push = [&](string s, int i, int j) { que.push(make_pair(s, make_pair(i, j))); }; Push("", 0, 0); while (true) { auto [s, p] = que.top(); auto [i, j] = p; que.pop(); s += grid[i][j]; if (i == h - 1 && j == w - 1) { cout << s << '\n'; return 0; } if (i + 1 < h) { Push(s, i + 1, j); } if (j + 1 < w) { Push(s, i, j + 1); } } return 0; }