#define _USE_MATH_DEFINES #include using namespace std; constexpr int INF = 1 << 30; signed main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector in(h); for (int i = 0; i < h; i++) cin >> in[i]; vector> dist(h, vector(w, INF)); dist[0][0] = 0; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { if (in[i][j] == 'k') { if (i > 0) dist[i][j] = min(dist[i][j], dist[i - 1][j] + j + i + 1); if (j > 0) dist[i][j] = min(dist[i][j], dist[i][j - 1] + j + i + 1); } else { if (i > 0) dist[i][j] = min(dist[i][j], dist[i - 1][j] + 1); if (j > 0) dist[i][j] = min(dist[i][j], dist[i][j - 1] + 1); } } cout << dist[h - 1][w - 1] << '\n'; return 0; }