#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) int(x.size())
const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const ll linf = 9e18 + 5;
const ll ll0 = 0 * 1ll;


int n, m;
vector<string> arr;

const int N = 4e5 + 5;
int parr[N];
bool visited[N];

int top[N];

vector<int> posi[N];
vector<int> negi[N];

int deg[N];

stack<int> dfs_order;

int code (int x, int y) {
    return (x - 1) * m + y - 1;
}

void init () {
}

void input () {
    cin >> n >> m;
    arr.resize(n + 2);

    string emp = "";
    for (int i = 0; i < m + 2; i++) {
        emp += '.';
    }

    arr[0] = emp;
    for (int i = n; i > 0; i--) {
        cin >> arr[i];

        arr[i] = '.' + arr[i] + '.';
    }
    arr[n + 1] = emp;

    for (int i = 0; i < m; i++) {
        int useless;
        cin >> useless;
    }
}

void dfs (int u) {
    visited[u] = true;

    for (auto v : posi[u]) {
        if (!visited[v]) {
            dfs(v);
        }
    }

    dfs_order.push(u);
}

void dfs2 (int u, int p) {
    parr[u] = p;

    for (auto v : negi[u]) {
        if (parr[v] == -1) {
            dfs2(v, p);
        }
    }
}

void solve() {
    fill(top, top + m + 2, -1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (arr[i][j] == '#') {
                if (arr[i][j + 1] == '#') {
                    posi[code(i, j)].pb(code(i, j + 1));
                    negi[code(i, j + 1)].pb(code(i, j));
                }
                if (arr[i][j - 1] == '#') {
                    posi[code(i, j)].pb(code(i, j - 1));
                    negi[code(i, j - 1)].pb(code(i, j));
                }
                if (arr[i + 1][j] == '#') {
                    posi[code(i, j)].pb(code(i + 1, j));
                    negi[code(i + 1, j)].pb(code(i, j));
                }
                if (arr[i - 1][j] == '#') {
                    posi[code(i, j)].pb(code(i - 1, j));
                    negi[code(i - 1, j)].pb(code(i, j));
                }

                for (int k = -1; k <= 1; k++) {
                    if (top[j + k] != -1) {
                        posi[code(i, j)].pb(code(top[j + k], j + k));
                        negi[code(top[j + k], j + k)].pb(code(i, j));
                    }
                }
            }
        }
        for (int j = 1; j <= m; j++) {
            if (arr[i][j] == '#') {
                top[j] = i;
            }
        }
    }


    fill(parr, parr + N, -1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (!visited[code(i, j)] && arr[i][j] == '#') {
                dfs(code(i, j));
            }
        }
    }

    while (!dfs_order.empty()) {
        int u = dfs_order.top();
        dfs_order.pop();

        if (parr[u] == -1) {
            dfs2(u, u);
        }
    }

    for (int i = 0; i < n * m; i++) {
        for (auto v : posi[i]) {
            if (parr[v] != parr[i]) {
                deg[parr[v]]++;
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < n * m; i++) {
        if (parr[i] == i && deg[i] == 0) {
            ans++;
        }
    }

    cout << ans;
}

void output() {
}

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

    int number_of_testcases = 1;
    //cin >> number_of_testcases;
    while (number_of_testcases--) {
        init();

        input();

        solve();

        output();
    }

    return 0;
}
