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