from sys import stdin def main(): input = lambda: stdin.readline()[:-1] H, W = map(int, input().split()) A = stdin.read().splitlines() grid = [[0] * W for _ in [0] * H] for i in range(1, W): grid[0][i] = grid[0][i-1] + 1 if A[0][i] == 'k': grid[0][i] *= 2 for i in range(1, H): grid[i][0] = grid[i-1][0] + 1 if A[i][0] == 'k': grid[i][0] *= 2 for i in range(1, H): for j in range(1, W): grid[i][j] = min(grid[i][j-1] + 1, grid[i-1][j] + 1) if A[i][j] == 'k': grid[i][j] *= 2 print(grid[H-1][W-1]) main()