#include<bits/stdc++.h>
using namespace std;
namespace jyy{
	const int mod=998244353,N=500010;
	const double eps=1e-8;
	#define ll long long
	inline int read(){
		static int x=0,f=1;x=0,f=1;
		static char ch=getchar();
		while(ch<'0'||ch>'9'){(ch=='-')?f*=-1:f;ch=getchar();}
		while(ch>='0'&&ch<='9')x=x*10+int(ch-48),ch=getchar();
		return x*f;
	}
	inline void fw(int x){if(x<0)putchar('-'),x=-x;x>=10?fw(x/10),1:0;putchar(char(x%10+48));}
	int qmo(int x){return x+((x>>31)&mod);}
	int ksm(int x,int y){int tmp=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)tmp=1ll*tmp*x%mod;return tmp;}
	int inv(int x){return ksm(x,mod-2);}
	int tot,head[N],fa[N];
	struct edge{int to,next;}dat[N*8];
	void add_edge(int x,int y){dat[++tot]=(edge){y,head[x]},head[x]=tot;}
	int find(int x){return fa[x]?fa[x]=find(fa[x]):x;}
	void merge(int x,int y){find(x)!=find(y)?fa[find(x)]=find(y):0;}
	int ifac[N],fac[N];
	void init(int x){fac[0]=ifac[0]=1;for(int i=1;i<=x;i++)fac[i]=1ll*fac[i-1]*i%mod;ifac[x]=inv(fac[x]);for(int i=x-1;i>=1;i--)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;}
}
using namespace jyy;
int n,m,z,vis[N],dfn[N],low[N],cnt,s[N],col[N],color,de[N];
char c[N];
vector<int>v[N],D[N];
int id(int x,int y){
	return (x-1)*m+y;
}
void tarjan(int x){
	vis[x]=1;
	dfn[x]=low[x]=++cnt;
	s[++z]=x;
	for(int i=head[x];i;i=dat[i].next){
		int t=dat[i].to;
		if(vis[t]==0)tarjan(t),low[x]=min(low[x],low[t]);
		else if(vis[t]==1)low[x]=min(low[x],dfn[t]);
	}
	if(low[x]==dfn[x]){
		int p=0;
		color++;
		while(p!=x){
			p=s[z--];
			vis[p]=-1;
			col[p]=color;
		}
	}
}
void solve(){
	n=read(),m=read();
	for(int i=1;i<=n;i++){
		scanf("%s",c+1);
		v[i].push_back(0);
		for(int j=1;j<=m;j++)v[i].push_back((c[j]=='#'));
	}
	for(int i=1;i<=n;i++)D[i].assign(m+1,0);
	for(int i=1;i<=m;i++){
		D[n][i]=(v[n][i])?n:n+1;
		for(int j=n-1;j>=1;j--)D[j][i]=(v[j][i])?j:D[j+1][i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(!v[i][j])continue;
			if(i!=n&&D[i+1][j]!=n+1)add_edge(id(i,j),id(D[i+1][j],j));
			if(i!=1&&v[i-1][j])add_edge(id(i,j),id(i-1,j));
			if(j!=1&&D[i][j-1]!=n+1)add_edge(id(i,j),id(D[i][j-1],j-1));
			if(j!=m&&D[i][j+1]!=n+1)add_edge(id(i,j),id(D[i][j+1],j+1));
		}
	}
//	cout<<"check "<<endl;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(!vis[id(i,j)]&&v[i][j])tarjan(id(i,j));
		}
	}
	for(int i=1;i<=n*m;i++){
		if(!vis[i])continue;
		for(int j=head[i];j;j=dat[j].next){
			int t=dat[j].to;
			if(col[i]!=col[t])de[col[t]]++;
		}
	}
	int ans=0;
	for(int i=1;i<=color;i++)if(!de[i])ans++;
	cout<<ans;
}
int T;
int main(){
	if(0)cin>>T;
	else T=1;
	while(T--)solve();
}

