#include using namespace std; int dp[2000][2000]; int main(){ int h,w;cin>>h>>w; char mp[h][w]; for(int i = 0; h > i; i++){ for(int j = 0; w > j; j++){ cin>>mp[i][j]; } } dp[0][0] = 0; for(int i = 0; h > i; i++){ for(int j = 0; w > j; j++){ if(!(i+j))continue; if(!i){ dp[i][j] = dp[i][j-1]+1; }else if(!j){ dp[i][j] = dp[i-1][j]+1; }else{ dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1; } if(mp[i][j] == 'k')dp[i][j]*=2; } } cout << dp[h-1][w-1] << endl; }