H, W = list(map(int, input().split())) a_list = [[s for s in input()] for i in range(H)] dp_list = [[0 for i in range(W)] for j in range(H)] for h in range(H): for w in range(W): if h > 0 and w > 0: dp_list[h][w] = min([dp_list[h - 1][w], dp_list[h][w - 1]]) dp_list[h][w] += (1 + h + w) if a_list[h][w] == "k" else 1 elif h > 0: dp_list[h][w] = dp_list[h - 1][w] dp_list[h][w] += (1 + h + w) if a_list[h][w] == "k" else 1 elif w > 0: dp_list[h][w] = dp_list[h][w - 1] dp_list[h][w] += (1 + h + w) if a_list[h][w] == "k" else 1 else: continue print(dp_list[-1][-1])