#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 #define MOD 1000000007 //#define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 using ll = long long; using Pi = pair; using Pl = pair; ll dp[2020][2020]; int main(){ int H,W; cin >> H >> W; vector a(H); rep(i,H) cin >> a[i]; rep(i,2020)rep(j,2020) dp[i][j] = LINF; dp[0][0] = 0; rep(i,H)rep(j,W){ if(i+1 < H){ if(a[i+1][j] == '.') 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]+i+j+2); } if(j+1 < W){ if(a[i][j+1] == '.') 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]+i+j+2); } } //rep(i,H)rep(j,W) cout << dp[i][j] << endl; cout << dp[H-1][W-1] << endl; }