/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.20 15:27:07
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int h,w;cin >> h >> w;
    vector<string> g(h);
    for (int i = 0; i < h; i++) {
        cin >> g[i];
    }
    constexpr int INF = 1e9 + 6;
    vector<vector<int>> dp(h,vector<int>(w,INF));
    dp[0][0] = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (g[i][j] == 'k') {
                if (j-1 >= 0) dp[i][j] = min(dp[i][j],dp[i][j-1] + i + j + 1);
                if (i-1 >= 0) dp[i][j] = min(dp[i][j],dp[i-1][j] + i + j + 1);
            }
            else {
                if (j-1 >= 0) dp[i][j] = min(dp[i][j],dp[i][j-1] + 1);
                if (i-1 >= 0) dp[i][j] = min(dp[i][j],dp[i-1][j] + 1);
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}