#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; void solve() { int H, W; cin >> H >> W; vector A(H); rep(y, H) { cin >> A[y]; } const int INF = INT_MAX / 3; vector mi(H, vi(W, INF)); mi[0][0] = 0; auto f = [&](int y, int x) { return A[y][x] == 'k' ? y + x : 0; }; rep(y, H)rep(x, W) { if (y + 1 < H) { smin(mi[y + 1][x], mi[y][x] + f(y + 1, x) + 1); } if (x + 1 < W) { smin(mi[y][x + 1], mi[y][x] + f(y, x + 1) + 1); } } cout << mi[H - 1][W - 1] << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }