#include using namespace std; #include using namespace atcoder; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a& s){ for(int i=p-1;i<=p+1;i++)for(int j=q-1;j<=q+1;j++) if(s[i][j]=='#') return false; return true; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int h,w; cin >> h >> w; vector s(h); rep(i,h) cin >> s[i]; mf_graph g((h-2)*(w-2)); vector> seen(h,vector(w,false)); rep(i,h) seen[i][0] = seen[i][w-1] = true; rep(i,w) seen[0][i] = seen[h-1][i] = true; queue> que; que.push({1,1}); seen[1][1] = true; while(que.size()){ int p,q; tie(p,q) = que.front(); que.pop(); rep(i,8){ int np = p+H[i], nq = q+W[i]; if(seen[np][nq] || !f(np,nq,s)) continue; seen[np][nq] = true; g.add_edge((p-1)*(w-2)+(q-1), (np-1)*(w-2)+(nq-1),1); g.add_edge((np-1)*(w-2)+(nq-1), (p-1)*(w-2)+(q-1),1); que.push({np,nq}); } } cout << g.flow(0, (h-2)*(w-2)-1) << '\n'; return 0; }