import java.util.*; public class Main { static final int MOD = 1000000007; 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][]; long[][] counts = new long[h + 1][w + 1]; Arrays.fill(counts[0], Long.MAX_VALUE / 10); for (int i = 0; i < h; i++) { field[i] = sc.next().toCharArray(); counts[i + 1][0] = Long.MAX_VALUE / 10; } counts[0][1] = -1; counts[1][0] = -1; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { counts[i][j] = Math.min(counts[i - 1][j], counts[i][j - 1]) + 1; if (field[i - 1][j - 1] == 'k') { counts[i][j] += i - 1 + j - 1; } } } System.out.println(counts[h][w]); } }