#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,avx2")
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
#define umap unordered_map
#define uset unordered_set
#define PI 3.14159265358979323846
#define E  2.71828182845904523536
#define nl '\n'
#define LINF (ll)1e18
#define INF (1 << 30)
#define eps 1e-10
#define dbx(x) cout << x << endl;
#define dbn(x) cout << x << nl;


const int MAXN = 4e5 + 5;
string s[MAXN];
int x[MAXN];
#define h(x,y) (((ll)(x) << 30) | (y))
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
vi e[MAXN];
int ok[MAXN], g[MAXN], idx[MAXN], low[MAXN];
bool onst[MAXN];
stack<int> st;
int ix = 1, gx = 1;
void scc(int v){
	idx[v] = ix;
	low[v] = ix;
	ix++;
	st.push(v);
	onst[v] = true;
	for(int w : e[v]){
		if(idx[w] == 0){
			scc(w);
			low[v] = min(low[v], low[w]);
		}else if(onst[w]){
			low[v] = min(low[v], idx[w]);
		}
	}
	if(low[v] == idx[v]){
		int k;
		do{
			k = st.top(); st.pop();
			onst[k] = false;
			g[k] = gx;
		}while(k != v);
		gx++;
	}
}
int main() {
    FASTIO;
    PRECISION;
    umap<ll, int> u;
    int kp = 1;
    int n, m; cin >> n >> m;
    for(int i = 0; i < n; i++){
    	cin >> s[i];
    	for(int j = 0; j < m; j++){
    		if(s[i][j] == '#'){
    			u[h(i,j)] = kp;
    			kp++;
    		}
    	}
    }
    int idc;
    for(int i = 0; i < m; i++){cin >> idc;}
    for(int j = 0; j < m; j++){
    	int l = 0;
    	for(int i = 0; i < n; i++){
    		if(s[i][j] == '#'){
				int nk = u[h(i,j)];
				if(l){
					e[l].push_back(nk);
					if(i && s[i - 1][j] == '#'){
						e[nk].push_back(l);
					}
				}
				l = nk;
			}
    		if(l){
    			if(j && s[i][j - 1] == '#'){
    				e[l].push_back(u[h(i, j - 1)]);
    			}
    			if(j != m - 1 && s[i][j + 1] == '#'){
    				e[l].push_back(u[h(i, j + 1)]);
    			}
    		}
    	}
    }
    for(int i = 1; i < kp; i++){
    	if(!g[i]){
    		scc(i);
    	}
    }
    
    for(int i = 1; i < kp; i++){
    	for(int j : e[i]){
    		if(g[i] != g[j]){
    			ok[g[j]] = true;
    		}
    	}
    }
    int ct = 0;
    for(int i = 1; i < gx; i++){
    	if(!ok[i]){ct++;}
    }
    cout << ct << nl;
}


