import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int w = sc.nextInt(); char[][] field = new char[h][]; for (int i = 0; i < h; i++) { field[i] = sc.next().toCharArray(); } int[][] costs = new int[h + 1][w + 1]; Arrays.fill(costs[0], Integer.MAX_VALUE / 10); for (int i = 2; i <= h; i++) { costs[i][0] = Integer.MAX_VALUE / 10; } for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { costs[i][j] = Math.min(costs[i - 1][j], costs[i][j - 1]) + 1; if (field[i - 1][j - 1] == 'k') { costs[i][j] += i + j - 2; } } } System.out.println(costs[h][w] - 1); } }