#include #define REP(i,n) for(int i=0,i##_len=int(n);i>H>>W; vector s(H); REP(i,H) cin>>s[i]; const int inf=1e9; vector> dp(H,vector(W,inf)); dp[0][0]=0; REP(i,H) REP(j,W){ int pl=1; if(s[i][j]!='.') pl+=i+j; if(i>0) dp[i][j]=min(dp[i][j],dp[i-1][j]+pl); if(j>0) dp[i][j]=min(dp[i][j],dp[i][j-1]+pl); } cout<