#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(int i=(a);i<(b);++i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define MOD 1000000007 int h,w; int d[1005][1005]; vector uf, usz; int nc; void init(int n){ vector uf_(n); vector usz_(n, 1); uf = uf_; usz = usz_; nc = n; for(int i = 0; i < uf.size(); i++){ uf[i] = i; } } int find(int a){ return (uf[a] == a) ? a : uf[a] = find(uf[a]); } void union_(int a, int b){ a = find(a); b = find(b); if(a != b){ if(usz[a] >= usz[b]){ swap(a, b); } uf[a] = b; usz[b] += usz[a]; nc--; } } int check(int a, int b){ return (find(a) == find(b)) ? 1 : 0; } int get_size(int a){ return usz[find(a)]; } int dd[1005][1005]; int d1[1005][1005]; int f(int a,int py,int px){ int dy[4] = {-1,0,0,1}; int dx[4] = {0,-1,1,0}; dd[py][px]=1; rep(i,0,4){ if(py+dy[i]<0)continue; if(py+dy[i]>=h)continue; if(px+dx[i]<0)continue; if(px+dx[i]>=w)continue; if(d[py+dy[i]][px+dx[i]]!=0){ d1[a][d[py+dy[i]][px+dx[i]]]=1; d1[d[py+dy[i]][px+dx[i]]][a]=1; continue; } if(dd[py+dy[i]][px+dx[i]]==1){ continue; } f(a,py+dy[i],px+dx[i]); } } vector > vg; vector vc; int dp[2][1005]; int f2(int p, int flag){ if(dp[flag][p]!=-1){ return dp[flag][p]; } if(flag == 0){ int ret = 0; rep(i,0,vg[p].sz){ ret += max(f2(vg[p][i],0),f2(vg[p][i],1)); } return dp[0][p] = ret; } else{ int ret = vc[p]; rep(i,0,vg[p].sz){ ret += f2(vg[p][i],0); } return dp[1][p] = ret; } } int main(){ cin>>h>>w; vector vs; rep(i,0,h){ string s; cin>>s; vs.pb(s); } clr(d,0); rep(y,0,h){ rep(x,0,w){ if(vs[y][x]=='x'){ d[y+1][x+1] = 1; } } } h+=2; w+=2; init(h*w); rep(y,1,h-1){ rep(x,1,w-1){ int dx[8]={-1,0,1,-1,1,-1,0,1}; int dy[8]={-1,-1,-1,0,0,1,1,1}; rep(i,0,8){ if(d[y][x]==1&&d[y+dy[i]][x+dx[i]]==1){ union_(w*y+x,w*(y+dy[i])+x+dx[i]); } } } } set se; rep(y,0,h){ rep(x,0,w){ if(d[y][x]==1){ int a = find(w*y+x); d[y][x]=a; se.insert(a); } } } vector vv(all(se)); map ma; rep(i,0,vv.sz){ ma[vv[i]]=i+1; } rep(y,0,h){ rep(x,0,w){ if(d[y][x]!=0){ d[y][x] = ma[d[y][x]]; } } } int nn = vv.sz; vector vc_(nn+1,0); vc = vc_; vector vy1(nn+1); vector vx1(nn+1); vc[0] = 0; vy1[0] = 0; vx1[0] = 0; rep(y,0,h){ rep(x,0,w){ if(d[y][x]!=0){ vy1[d[y][x]] = y; vx1[d[y][x]] = x; vc[d[y][x]]++; } } } vector > vp(nn+1,vector()); clr(d1,0); rep(i,0,nn+1){ clr(dd,0); f(i,vy1[i],vx1[i]); } vector vb(nn+1,0); vb[0] = 1; vector > vg_(nn+1,vector()); vg = vg_; rep(i,0,nn+1){ rep(j,i+1,nn+1){ if(d1[i][j]==1){ if(vb[j]==0){ vb[j]=1; vg[i].pb(j); } } } } clr(dp,-1); cout << f2(0,0) << endl; return 0; }