#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int h,w; cin>>h>>w; vector s(h); rep(i,h)cin>>s[i]; vector d(h,vector(w,Inf32)); deque> D; for(int i=h-3;i0){ int x = D.back().first,y = D.back().second; D.pop_back(); for(int i=-3;i<=3;i++){ for(int j=-3;j<=3;j++){ int xx = x+i,yy = y+j; if(xx<0||xx>=h||yy<0||yy>=w)continue; int cost = d[x][y]; if(s[xx][yy]=='.')cost++; if(xx<3&&yy<3)continue; if(xx>=h-3&&yy>=w-3)continue; if(d[xx][yy]<=cost)continue; d[xx][yy] = cost; if(s[xx][yy]=='.'){ D.emplace_front(xx,yy); } else D.emplace_back(xx,yy); } } } int ans = Inf32; rep(i,h-3){ for(int j=w-3;j