#include <bits/stdc++.h>
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())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

const int inf = 1LL<<60;

signed main() {
  int h, w;
  cin >> h >> w;

  vector<string> 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;
}