#include <bits/stdc++.h>
 
#define int long long

#define ext exit(0)
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228

#define data data228
 
#define pb push_back
#define eb emplace_back                                  
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << endl; 
#define TIME (ld)clock()/CLOCKS_PER_SEC
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 4e5 + 7, mod = 1e9 + 7, MAXN = 2e6 + 7;
const double eps = 1e-9;                                        
const ll INF = 1e18, inf = 1e15;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());                       
int n, m; 
vector<char> field[maxn]; 
vector<int> gr[maxn]; 
vector<int> rgr[maxn]; 
vector<int> yy[maxn]; 

void add(int x, int y, int x1, int y1) {
//    cout << x << " " << y << " " << x1 << " " << y1 << '\n'; 
    gr[x * m + y].pb(x1 * m + y1); 
}

int used[maxn]; 

vector<int> ord; 

void dfs(int u) {
    used[u] = 1; 
    for (auto v : gr[u]) {
        if (!used[v]) dfs(v); 
    }
    ord.pb(u); 
}

int color[maxn]; 

void dfs1(int u, int cl) {
    color[u] = cl; 
    for (auto v : rgr[u]) {
        if (!color[v]) {
            dfs1(v, cl); 
        }
    }
}

int deg[maxn]; 

void solve() {
    cin >> n >> m; 
    for (int i = 0; i < n; ++i) {
        field[i].resize(m); 
        for (int j = 0; j < m; ++j) {
            cin >> field[i][j]; 
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (field[i][j] == '#') {
                yy[j].pb(i); 
            }
        } 
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (field[i][j] != '#') continue; 
            if (i > 0 && field[i - 1][j] == '#') {
                add(i, j, i - 1, j); 
            }         
            int idx = lower_bound(all(yy[j]), i) - yy[j].begin(); 
            if (idx + 1 < (int)yy[j].size()) {
                add(i, j, yy[j][idx + 1], j); 
            }
            if (j > 0) {
                int L = lower_bound(all(yy[j - 1]), i) - yy[j - 1].begin(); 
                if (L < (int)yy[j - 1].size()) {
                    add(i, j, yy[j - 1][L], j - 1); 
                }
            }
            if (j + 1 < m) {
                int R = lower_bound(all(yy[j + 1]), i) - yy[j + 1].begin(); 
                if (R < (int)yy[j + 1].size()) {
                    add(i, j, yy[j + 1][R], j + 1); 
                }                
            }
        }
    }  
    for (int i = 0; i < n * m; ++i) {
        for (auto v : gr[i]) {
            rgr[v].pb(i);
        }
    }  
    for (int i = 0; i < n * m; ++i) {
        if (field[i / m][i % m] == '.') continue; 
        if (!used[i]) {
            dfs(i); 
        }
    }
    reverse(all(ord)); 
    int pt = 1; 
    for (auto v : ord) {
        if (!color[v]) {
            dfs1(v, pt); 
            ++pt; 
        }
    }
    /*
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cout << color[i * m + j] << " "; 
        }
        cout << '\n'; 
    }
    cout << '\n'; 
    */
    for (int i = 0; i < n * m; ++i) {
        for (auto v : gr[i]) {
            if (color[i] == color[v]) continue; 
            deg[color[v]]++; 
        }
    }    
    int ans = 0;
    for (int i = 1; i < pt; ++i) {
        if (deg[i] == 0) ++ans; 
    }
    cout << ans << '\n'; 
}                                
                 
signed main() {          
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif // LOCAL                                                                             
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  