#================================================== H,W=map(int,input().split()) A=[] for _ in range(H): A.append(list(map(lambda x:1 if x=="k" else 0,input()))+[-1]) A.append([-1]*(W+1)) inf=float("inf") DP=[[inf]*W for _ in range(H)]; DP[0][0]=0 for i in range(H): for j in range(W): if i!=H-1: if A[i+1][j]==0: DP[i+1][j]=min(DP[i+1][j],DP[i][j]+1) else: DP[i+1][j]=min(DP[i+1][j],DP[i][j]+1+((i+1)+j)) if j!=W-1: if A[i][j+1]==0: DP[i][j+1]=min(DP[i][j+1],DP[i][j]+1) else: DP[i][j+1]=min(DP[i][j+1],DP[i][j]+1+(i+(j+1))) print(DP[-1][-1])