/*
{
######################
#       Author       #
#        Gary        #
#        2021        #
######################
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
//inline int read(){
//    int x=0;
//    char ch=getchar();
//    while(ch<'0'||ch>'9'){
//        ch=getchar();
//    }
//    while(ch>='0'&&ch<='9'){
//        x=(x<<1)+(x<<3)+(ch^48);
//        ch=getchar();
//    }
//    return x;
//}
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int fa[1000+12];
int h,w;
char maze[1001][1001];
char maze2[1001][1001];
int root(int now){
	return fa[now]=(fa[now]==now? now:root(fa[now]));
}
int solve(){
	rb(i,1,h) fa[i]=i;
	maze[1][1]=maze[1][w]=maze[h][1]=maze[h][w]='#';
	rb(j,1,w){
		vector<int> have;
		rb(i,1,h){
			if(maze[i][j]=='#'){
				have.PB(i);
			}
		}
		rep(i,have.size()){
			if(i>0){
				fa[root(have[i])]=root(have[i-1]);
			}
		}
	}
	int cnt=0;
	rb(i,1,h){
		cnt+=(root(i)==i);
	}
	return cnt-1;
}
int main(){
	cin>>h>>w;
	if(min(h,w)<=2){
		cout<<0<<endl;
		return 0;
	}
	rb(i,1,h)
		rb(j,1,w)
			cin>>maze[i][j];
	int rest=solve();
	swap(h,w);
	rb(i,1,h)
		rb(j,1,w)
			maze2[i][j]=maze[j][i];
	rb(i,1,h)
		rb(j,1,w)
			maze[i][j]=maze2[i][j];
	check_min(rest,solve());
	cout<<rest<<endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
 
int H, W, ans = 0;
char S[15][15];
 
int main()
{
    cin >> H >> W;
    
    for(int i = 0; i < H; i++)
        for(int j = 0;j < W;j++)
            cin >> S[j][i];

    for(int i = 0; i < H - 1; i++)
    {
        for(int j = 0; j < W - 1; j++)
        {
            int b = 0, w = 0;

            if(S[j][i] == '#')
                b++;
            else
                w++;

            if(S[j+1][i] == '#')
                b++;
            else
                w++;

            if(S[j][i+1] == '#')
                b++;
            else
                w++;

            if(S[j+1][i+1] == '#')
                b++;
            else
                w++;

            if((b == 3 && w == 1) || (b == 1 && w == 3))
                ans++;
        }
    }
    cout << ans << endl;
}