import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); 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][w]; for (int[] arr : costs) { Arrays.fill(arr, Integer.MAX_VALUE); } PriorityQueue queue = new PriorityQueue<>(); queue.add(new Path(0, 0, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (field[p.r][p.c] == 'k') { p.value += p.r + p.c; } if (costs[p.r][p.c] <= p.value) { continue; } costs[p.r][p.c] = p.value; if (p.r < h - 1) { queue.add(new Path(p.r + 1, p.c, p.value + 1)); } if (p.c < w - 1) { queue.add(new Path(p.r, p.c + 1, p.value + 1)); } } System.out.println(costs[h - 1][w - 1]); } static class Path implements Comparable { int r; int c; int value; public Path(int r, int c, int value) { this.r = r; this.c = c; this.value = value; } public int compareTo(Path another) { return value - another.value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }