#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int INF = INT_MAX / 2; int main() { int h, w; cin >> h >> w; vector s(h); for(int y=0; y> s[y]; vector > dp(h, vector(w, INF)); dp[0][0] = 0; for(int y=0; y= h || x2 >= w) continue; if(s[y2][x2] == 'k') dp[y2][x2] = min(dp[y2][x2], dp[y][x] + y + x + 2); else dp[y2][x2] = min(dp[y2][x2], dp[y][x] + 1); } } } cout << dp[h-1][w-1] << endl; return 0; }