H,W = map(int,input().split()) A = [input() for i in range(H)] inf = 10**10 dis = [[inf]*W for i in range(H)] dis[0][0] = 0 for i in range(H): for j in range(W): cand = min(dis[i-1][j],dis[i][j-1]) if A[i][j] == "k": cand += i+j dis[i][j] = min(dis[i][j],cand+1) print(dis[-1][-1])