#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; typedef pair PL; constexpr int INF = 2e9; int main() { int h, w; cin >> h >> w; vector s(h); rep(i,h) cin >> s[i]; vector> dp(h, vector(w, INF)); dp[0][0] = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int cost = 1; if (s[i][j] == 'k') cost += i + j; if (i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + cost); if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + cost); } } cout << dp[h - 1][w - 1] << endl; return 0; }