#include using namespace std; #define int long long #define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++) #define all(x) (x).begin(),(x).end() #define sz(x) ((int)x.size()) templatebool chmax(T &a,T b){if(abool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;} /* */ using vi = vector; using vvi = vector; using P = pair; const int inf = 1LL<<60; signed main() { int h, w; cin >> h >> w; vector a(h); rep(i, 0, h) cin >> a[i]; vvi dp(h, vi(w, inf)); dp[0][0] = 0; rep(i, 0, h) rep(j, 0, w){ if(j+1 < w){ chmin(dp[i][j+1], dp[i][j] + (a[i][j+1] == 'k' ? i+j+2 : 1)); } if(i+1 < h){ chmin(dp[i+1][j], dp[i][j] + (a[i+1][j] == 'k' ? i+j+2 : 1)); } } cout << dp[h-1][w-1] << endl; return 0; }