#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define en cin.close();return 0;
#define INF ((ll)(2e18))
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 4e5+5;
vector<ll> g[N], rg[N];
ll comp[N], indeg[N];
bool vis[N];
ll dx[]={-1,1,0,0};
ll dy[]={0,0,1,-1};
stack<ll> st;
void dfs(ll u)
{
    vis[u]=1;
    for(auto v:g[u])
        if(!vis[v])
            dfs(v);
    st.push(u);
}
void dfs2(ll u, ll col)
{
    comp[u]=col;
    for(auto v:rg[u])
        if(!comp[v])
            dfs2(v,col);
}
int main()
{
    fio
    //ifstream cin("in.inn");
    ll n, m;
    cin >> n >> m;
    char gr[n+1][m+1];
    ll id[n+1][m+1], cid = 0;
    vector<pair<ll,ll> > edg;
    for(ll i = 1;i<=n;i++)
        for(ll j = 1;j<=m;j++)
            id[i][j]=-1;
    for(ll i = 1;i<=n;i++)
    {
        for(ll j = 1;j<=m;j++)
        {
            cin >> gr[i][j];
            if(gr[i][j]=='#')
                id[i][j]=++cid;
        }
    }
    for(ll i = n-1;i>0;i--)
        for(ll j = 1;j<=m;j++)
            if(id[i][j]==-1)
                id[i][j]=id[i+1][j];
    for(ll i = 1;i<=n;i++)
    {
        for(ll j = 1;j<=m;j++)
        {
            if(gr[i][j]=='#')
            {
                for(ll d = 0;d<4;d++)
                {
                    ll nwi = i+dx[d], nwj = j+dy[d];
                    if(nwi<1||nwj<1||nwi>n||nwj>m||
                       id[nwi][nwj]==-1||id[nwi][nwj]==id[i][j])
                        continue;
                    g[id[i][j]].pb(id[nwi][nwj]);
                    rg[id[nwi][nwj]].pb(id[i][j]);
                    edg.pb({id[i][j],id[nwi][nwj]});
                }
            }
        }
    }
    for(ll i = 1;i<=cid;i++)
        if(!vis[i])
            dfs(i);
    vector<ll> nod;
    while(!st.empty())
    {
        ll u = st.top();
        st.pop();
        if(comp[u])
            continue;
        dfs2(u,u);
        nod.pb(u);
    }
    for(auto i:edg)
        if(comp[i.fi]!=comp[i.se])
            indeg[comp[i.se]]++;
    ll res = 0;
    for(auto i:nod)
        res+=(!indeg[i]);
    cout << res;
    //cin.close();
    return 0;
}
