H,W = map(int,input().split()) lsHW = [input() for i in range(H)] inf = float('INF') dp = [[inf]*W for i in range(H)] dp[0][0] = 0 for i in range(1,W): dp[0][i] = dp[0][i-1] + 1 if lsHW[0][i] == 'k': dp[0][i] += i for i in range(1,H): dp[i][0] = dp[i-1][0] + 1 if lsHW[i][0] == 'k': dp[i][0] += i for i in range(1,H): for j in range(1,W): dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1 if lsHW[i][j] == 'k': dp[i][j] += i+j print(dp[H-1][W-1])