#include using namespace std; using i64 = long; signed main() { int h, w; cin >> h >> w; vector a(h); for (auto &x : a) cin >> x; vector> dp(h, vector(w, 1e9)); for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j){ if(i == 0 && j == 0){ dp[i][j] = 0; continue; } int res = 1e9; if(i) res = min(res, dp[i - 1][j] + 1); if(j) res = min(res, dp[i][j - 1] + 1); if(a[i][j] == 'k') res += i + j; dp[i][j] = res; } cout << dp.back().back() << endl; }