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