#include #define llint long long #define inf 1e18 using namespace std; llint h, w; char c[2005][2005]; llint dp[2005][2005]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w; for(int y = 1; y <= h; y++){ for(int x = 1; x <= w; x++){ cin >> c[x][y]; } } for(int y = 1; y <= h; y++){ for(int x = 1; x <= w; x++){ dp[x][y] = inf; } } dp[1][1] = 0; for(int y = 1; y <= h; y++){ for(int x = 1; x <= w; x++){ llint cost = 1; if(c[x][y] == 'k') cost += (x-1)+(y-1); if(x >= 2) dp[x][y] = min(dp[x][y], dp[x-1][y] + cost); if(y >= 2) dp[x][y] = min(dp[x][y], dp[x][y-1] + cost); } } cout << dp[w][h] << endl; return 0; }