#include using namespace std; int main() { const int inf = 1000000000; int h, w; cin >> h >> w; vector a(h); for (int i = 0; i < h; i++) cin >> a[i]; vector> cost(h, vector(w, inf)); cost[0][0] = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int k = (a[i][j] == 'k') ? i + j : 0; if (i > 0) { cost[i][j] = min(cost[i][j], cost[i - 1][j] + 1 + k); } if (j > 0) { cost[i][j] = min(cost[i][j], cost[i][j - 1] + 1 + k); } } } cout << cost[h - 1][w - 1] << endl; }