#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>

#define fi first
#define se second
#define ld long double
#define ll long long
#define int ll
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mpa make_pair
#define eb emplace_back
#define ve vector
#define pii pair<int, int>
#define sz(v) (int)(v).size()
#define forn(i, n) for (int i = 0; i < n; ++i)
using namespace std;
mt19937 gen(time(0));
mt19937 gen2(228);
mt19937_64 gen64(time(0));


ve<ve<int>> g(400005);
ve<ve<int>> gr(400005);
ve<int> used(400005);
ve<int> order;
void ts(int v) {
    used[v] = 1;
    for (auto to : g[v]) {
        if (!used[to]) {
            ts(to);
        }
    }
    order.eb(v);
}

ve<int> used2(400005, -1);
void color(int v, int c) {
    used2[v] = c;
    for (auto to : gr[v]) {
        if (used2[to] == -1) {
            color(to, c);
        }
    }
}

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

    int n, m;
    cin >> n >> m;
    ve<string> a(n);
    forn(i, n) cin >> a[i];
    ve<int> b(m);
    forn(i, m) cin >> b[i];
    function<int(int, int)> id = [&](int i, int j) {
        return i * m + j;
    };
    function<void(int, int)> me = [&](int i, int j) {
        //cout << i << " -> " << j << endl;
        g[i].eb(j);
        gr[j].eb(i);
    };
    ve<int> dx = {0, 0, 1, -1};
    ve<int> dy = {1, -1, 0, 0};

    forn(j, m) {
        ve<int> bestH = {n, n, n};
        for (int i = n - 1; i > -1; --i) {

            if (a[i][j] == '#') {
                for (int z = -1; z <= 1; ++z) {
                    if (bestH[z + 1] != n) {
                        //cout << " ??? " << id(i, j) << " " << id(bestH[z + 1], j) << endl;
                        me(id(i, j), id(bestH[z + 1], j + z));
                    }
                }
                for (int k = 0; k < 4; ++k) {
                    int nx = i + dx[k];
                    int ny = j + dy[k];
                    if (-1 < nx && nx < n && -1 < ny && ny < m && a[nx][ny] == '#') {
                        //cout << " ??? " << id(i, j) << " -> " << id(nx, ny) << endl;
                        me(id(i, j), id(nx, ny));
                    }
                }
            }
            for (int z = -1; z <= 1; ++z) {
                if (-1 < z + j && z + j < m) {
                    if (a[i][z + j] == '#') {
                        bestH[z + 1] = min(bestH[z + 1], i);
                    }
                }
            }
        }
    }
    forn(i, n) {
        forn(j, m) {
            if (a[i][j] == '#') {
                if (!used[id(i, j)]) {
                    ts(id(i, j));
                }
            }
        }
    }
    int fcolor = 0;
    reverse(all(order));
    forn(i, sz(order)) {
        if (used2[order[i]] == -1) {
            color(order[i], fcolor++);
        }
    }
    forn(i, n) {
        forn(j, m) {
            if (a[i][j] == '#') {
                //cout << id(i, j) << " " << used2[id(i, j)] << endl;
            }
        }
    }
    int ans = 0;
    ve<int> indeg(fcolor);
    forn(i, n * m) {
        for (auto to : g[i]) {
            if (used2[i] != used2[to]) {
                indeg[used2[to]]++;
            }
        }
    }
    forn(i, fcolor) if (!indeg[i]) ++ans;
    cout << ans << '\n';
}
