#include <bits/stdc++.h>
using namespace std;

vector<vector<bool>> masu(10,vector<bool>(10));
int h,w;

int main(){
  char s;
  int ans=0;
  bool a,b,c,d;
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>s;
      if(s=='#'){
        masu.at(i).at(j)=true;
      }else{
        masu.at(i).at(j)=false;
      }
    }
  }
  for(int i=1;i<h-1;i++){
    for(int j=1;j<w-1;j++){
      if(masu.at(i).at(j)){
      a=masu.at(i-1).at(j-1);
      b=masu.at(i-1).at(j);
      c=masu.at(i-1).at(j+1);
      d=masu.at(i).at(j-1);
      if(!a&&!b&&c&&!d)ans+=2;
      if(a&&b&&!c&&!d)ans+=2;
      if(a&&!b&&!c&&d)ans+=2;
      if(!a&&b&&c&&!d)ans+=2;
      if(!a&&!b&&c&&d)ans-=2;
      if(a&&b&&c&&!d)ans+=4;
      if(a&&b&&!c&&d)ans-=2;
      if(!a&&b&&c&&d)ans+=2;
      if(!a&&!b&&!c&&!d)ans+=4;
     // cout<<"("<<i<<","<<j<<") ans="<<ans<<"abcd"<<a<<b<<c<<d<<endl;
      }
    }
  }
  cout<<ans<<endl;
}
  
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
#include <utility>


using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}



int main(void){
	int i,j,H,W;cin>>H>>W;
	vector<string>s(H);
	for(i=0;i<H;i++){cin>>s[i];}
	s[0][0]='#';
	s[0][W-1]='#';
	s[H-1][0]='#';
	s[H-1][W-1]='#';
	//地面の連結成分を数える
	vector<int>renR(H);
	vector<int>renC(W);
	queue<int>que;
	int rs=0;
	int Rx=0,Cx=0;
	for(i=0;i<H+W;i++){
		if(i<H){
			if(renR[i]!=0){continue;}
			bool aru=0;
			for(j=0;j<W;j++){
				if(s[i][j]=='#'){aru=1;break;}
			}
			if(!aru){Rx++;continue;}
			rs++;
			renR[i]=rs;
			que.push(i);
		}else{
			if(renC[i-H]!=0){continue;}
			bool aru=0;
			for(j=0;j<H;j++){
				if(s[j][i-H]=='#'){aru=1;break;}
			}
			if(!aru){Cx++;continue;}
			rs++;
			renC[i-H]=rs;
			que.push(i);
		}
		while(que.size()){
			if(que.front()<H){
				int t=que.front();
				que.pop();
				for(j=0;j<W;j++){
					if(renC[j]==0&&s[t][j]=='#'){
						renC[j]=renR[t];
						que.push(j+H);
					}
				}
			}else{
				int t=que.front()-H;
				que.pop();
				for(j=0;j<H;j++){
					if(renR[j]==0&&s[j][t]=='#'){
						renR[j]=renC[t];
						que.push(j);
					}
				}
			}
		}
	}
	//for(i=0;i<H;i++){cerr<<renR[i]<<" ";}
	//for(i=0;i<W;i++){cerr<<renC[i]<<" ";}
	//cerr<<endl;
	cout<<rs-1+min(Rx,Cx)<<endl;
}

