#define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <vector> #include <array> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> #include <iterator> #include <memory> #include <regex> using namespace std; const int INF = INT_MAX / 2; int main() { int h, w; cin >> h >> w; vector<string> s(h); for(int y=0; y<h; ++y) cin >> s[y]; vector<vector<int> > dp(h, vector<int>(w, INF)); dp[0][0] = 0; for(int y=0; y<h; ++y){ for(int x=0; x<w; ++x){ for(int i=0; i<2; ++i){ int y2 = y + i; int x2 = x + (i ^ 1); if(y2 >= 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; }