#include using namespace std; using ll = long long; constexpr ll INF = 1e18; int H, W; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> H >> W; vector a(H); for (int i = 0; i < H; ++i) { cin >> a[i]; } vector< vector > ans(H, vector(W, INF)); ans[0][0] = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (i + 1 < H) { ll cost = ans[i][j] + 1; if (a[i + 1][j] == 'k') cost += i + 1 + j; ans[i + 1][j] = min(ans[i + 1][j], cost); } if (j + 1 < W) { ll cost = ans[i][j] + 1; if (a[i][j + 1] == 'k') cost += i + 1 + j; ans[i][j + 1] = min(ans[i][j + 1], cost); } } } cout << ans[H - 1][W - 1] << "\n"; return 0; }