#include using namespace std; typedef pair P; #define INF 1000000 int H, W; char a[2100][2100]; int dist[2100][2100]; void dijkstra() { for (int i=0; i, greater

> pq; pq.push(P(0, 0)); while (pq.size()) { P p = pq.top(); pq.pop(); int d = p.first; int v = p.second; int x = v/W, y = v%W; if (dist[x][y]dist[x][y]+w) { dist[x+1][y] = dist[x][y]+w; pq.push(P(dist[x+1][y], W*(x+1)+y)); } } if (ydist[x][y]+w) { dist[x][y+1] = dist[x][y]+w; pq.push(P(dist[x][y+1], W*x+y+1)); } } } } int main() { cin >> H >> W; for (int i=0; i> a[i][j]; dijkstra(); cout << dist[H-1][W-1] << endl; }