H,W=map(int,input().split()) A=[input() for h in range(H)] inf=1<<30 dp=[[inf]*W for h in range(H)] dp[0][0]=0 for h in range(H): for w in range(W): if h: dp[h][w]=min(dp[h][w],dp[h-1][w]+1) if w: dp[h][w]=min(dp[h][w],dp[h][w-1]+1) if A[h][w]=="k": dp[h][w]+=h+w ans=dp[H-1][W-1] print(ans)