#include <bits/stdc++.h>

using namespace std;

#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 4e5+5;

int n , m , nodeNum , sz=1 , timer , aa[N] , in[N] , out[N] , com[N] , inStack[N] , low[N] , par[N];
int dx[4]={0,0,1,-1} , dy[4]={1,-1,0,0};

map<int , int> id[N] , new_id;
vector<char> a[N];
vector<int> adj[N];
set<int> st[N];
stack<int> nodes;

bool valid(int i , int j)
{
    if (i < 1 || i > n || j < 1 || j > m || a[i][j]!='#') return 0;
    return 1;
}

void get(int i , int j , int jj)
{
    auto it = st[jj].upper_bound(i);
    if (it != st[jj].end()) adj[id[i][j]].push_back(id[*it][jj]);
}

void tarjan(int node)
{
    in[node] = low[node] = ++timer;
    inStack[node] = 1;
    nodes.push(node);

    for(auto ch : adj[node])
    {
        if (!in[ch])
        {
            tarjan(ch);
            low[node] = min(low[node] , low[ch]);
        }
        else if (inStack[ch])
        {
            low[node] = min(low[node] , in[ch]);
        }
    }

    if (in[node] == low[node])
    {
        nodeNum++;
        while(nodes.size())
        {
            int cur = nodes.top();
            inStack[cur] = 0;
            nodes.pop();
            new_id[cur] = nodeNum;
            if (cur==node) break;
        }
    }
}
//

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    for(int i=1; i<=n; i++)
    {
        a[i] = vector<char>(m+2);
        for(int j=1; j<=m; j++)
        {
            cin >> a[i][j];
            if (a[i][j] == '#')
            {
                st[j].insert(i);
                id[i][j] = sz;
                sz++;
            }
        }
    }
    sz--;

    for(int i=1; i<=m; i++)
        cin >> aa[i];

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if (a[i][j] != '#') continue;
            get(i,j,j);
            if (j > 1) get(i,j,j-1);
            if (j<m) get(i,j,j+1);

            for(int k=0; k<4; k++)
            {
                int ii=i+dx[k] , jj=j+dy[k];
                if (valid(ii,jj))
                {
                    int node = id[i][j] , ch = id[ii][jj];
                    adj[node].push_back(ch);
                }
            }
        }
    }

    for(int i=1; i<=sz; i++)
    {
        if (!in[i]) tarjan(i);
    }

    for(int i=1; i<=sz; i++)
    {
        for(auto ch : adj[i])
        {
            if (new_id[i] == new_id[ch]) continue;
            par[new_id[ch]] = 1;
        }
    }

    int ans=0;
    for(int i=1; i<=nodeNum; i++)
    {
        if (!par[i]) ans++;
    }

    cout << ans << '\n';

    return 0;
}