#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; int dh[]={1,0,-1,0}; int dw[]={0,1,0,-1}; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int h,w; cin>>h>>w; vector S(h); rep(i,h) cin>>S[i]; queue> que; que.push({0,0}); vector> dist(h,vector(w,-1)); dist[0][0]=1; while(que.size()){ auto a=que.front(); que.pop(); int i=a.first,j=a.second; rep(k,4){ int ni=i+dh[k],nj=j+dw[k]; if(ni<0 || nj<0 || ni>=h-2 || nj>=w-2) continue; bool b=true; rep(l,3) rep(m,3){ if(S[ni+l][nj+m]=='#') b=false; } if(b==false) continue; if(dist[ni][nj]==-1){ dist[ni][nj]=1; que.push({ni,nj}); } } } if(dist[h-3][w-3]==-1){ cout<<0<=h-3 && j>=w-3) continue; if(S[i][j]=='#') continue; S[i][j]='#'; queue> que1; que1.push({0,0}); vector> dist1(h,vector(w,-1)); dist1[0][0]=1; while(que1.size()){ auto a=que1.front(); que1.pop(); int i=a.first,j=a.second; rep(k,4){ int ni=i+dh[k],nj=j+dw[k]; if(ni<0 || nj<0 || ni>=h-2 || nj>=w-2) continue; bool b=true; rep(l,3) rep(m,3){ if(S[ni+l][nj+m]=='#') b=false; } if(b==false) continue; if(dist1[ni][nj]==-1){ dist1[ni][nj]=1; que1.push({ni,nj}); } } } if(dist1[h-3][w-3]==-1){ cout<<1<