#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int main() { int h, w; cin >> h >> w; string s[h]; rep(i,h)cin >> s[i]; ll a[h][w]; rep(i,h)rep(j,w)a[i][j] = 0; rep(i,h){ rep(j,w){ if(i == 0 && j == 0)continue; if(i == 0){ a[i][j] = a[i][j-1] + 1; if(s[i][j-1] == 'k'){ a[i][j] += i + j - 1; } }else if(j == 0){ a[i][j] = a[i-1][j] + 1; if(s[i-1][j] == 'k'){ a[i][j] += i - 1 + j; } }else{ ll tmp1 = a[i][j-1] + 1; if(s[i][j-1] == 'k'){ tmp1 += i + j - 1; } ll tmp2 = a[i-1][j] + 1; if(s[i-1][j] == 'k'){ tmp2 += i - 1 + j; } a[i][j] = min(tmp1, tmp2); } } } cout << a[h-1][w-1] << endl; return 0; }