#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

char a[2000][2001];
int d[2000][2000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int h, w;
    cin >> h >> w;

    for (int i = 0; i < h; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int t0 = i > 0 ? d[i - 1][j] : 1 << 30;
            int t1 = j > 0 ? d[i][j - 1] : 1 << 30;
            int t = min(t0, t1) + 1;
            if (a[i][j] == 'k') t += i + j;
            if (i == 0 && j == 0) t = 0;
            d[i][j] = t;
        }
    }

    cout << d[h - 1][w - 1] << endl;

    return 0;
}