#include using namespace std; typedef long long ll; signed main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int h,w; cin>>h>>w; string s[h]; for(int i=0;i>s[i]; priority_queue,vector>,greater>> q; q.push({0,0,0}); int dx[2] = {1,0}; int dy[2] = {0,1}; int ans[h][w]; for(int i=0;i p = q.top(); q.pop(); if(ans[p[1]][p[2]] < p[0]) continue; for(int i=0;i<2;i++){ int x = p[1]+dx[i], y = p[2] + dy[i]; if((unsigned int)x < h && (unsigned int)y < w){ int ret; if(s[x][y]=='.') ret = p[0]+1; else{ ret = x+y+p[0]+1; } if(ans[x][y] > ret){ ans[x][y] = ret; q.push({ret,x,y}); } } } } cout << ans[h-1][w-1] << endl; }