#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

struct Dinic {
	struct edge{int to;long long cap,rev;};
	vector<vector<edge>> G;
	vector<int> level;
	vector<int> iter;

	Dinic(int n):G(n, vector<edge>()),level(n),iter(n){}

	void add_edge(int from,int to,long long cap){
		G[from].push_back((edge){to,cap,(ll)G[to].size()});
		G[to].push_back((edge){from,0,(ll)G[from].size()-1});
	}

	void bfs(int s){
		fill(level.begin(), level.end(), -1);
		queue<int> que;
		level[s] = 0;
		que.push(s);
		while(!que.empty())	{
			int v = que.front();que.pop();
			for(int i = 0;i < G[v].size();++i){
				edge &e = G[v][i];
				if(e.cap > 0 && level[e.to] < 0){
					level[e.to] = level[v] + 1;
					que.push(e.to);
				}
			}
		}
	}

	int dfs(int v ,int t,long long f){
		if(v == t)return f;
		for(int &i = iter[v];i < G[v].size() ;++i){
			edge &e = G[v][i];
			if(e.cap > 0 && level[v] < level[e.to]){
				long long d = dfs(e.to,t,min(f,e.cap));
				if(d > 0){
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	long long solve(int s,int t){
		long long flow = 0;
		while(1){
			bfs(s);
			if(level[t] < 0)return flow;
			fill(iter.begin(), iter.end(), 0);
			long long f;while((f = dfs(s,t,INF)) > 0)flow += f;
		}
	}
};

int getCount(int h, int w, vector<vector<char>> &mp){
	if(h < 0 || w < 0 || h + 1 >= mp.size() || w + 1 >= mp[0].size()) {
		return -1;
	}

	int cou = 0;
	if(mp[h][w] == '#')cou++;
	if(mp[h+1][w] == '#')cou++;
	if(mp[h][w+1] == '#')cou++;
	if(mp[h+1][w+1] == '#')cou++;
	return cou;
}

P searchPairTate(int h, int w, vector<vector<char>> &mp){
	while(1) {
		h++;
		if(mp[h][w] != '#' || mp[h][w+1] != '#'){
			return MP(-1, -1);
		}
		if(getCount(h, w, mp) != 4) {
			break;
		}
	}
	if(getCount(h, w, mp) == 3){
		return MP(h, w);
	}
	else {
		return MP(-1, -1);
	}
}

P searchPairYoko(int h, int w, vector<vector<char>> &mp){
	while(1) {
		w++;
		if(mp[h][w] != '#' || mp[h+1][w] != '#'){
			return MP(-1, -1);
		}
		if(getCount(h, w, mp) != 4) {
			break;
		}
	}
	if(getCount(h, w, mp) == 3){
		return MP(h, w);
	}
	else {
		return MP(-1, -1);
	}
}

bool intersect(pair<P, P> a, pair<P, P> b){
	if(b.FI.SE < a.FI.SE || b.FI.SE > a.SE.SE){
		return false;
	}
	if(a.FI.FI < b.FI.FI || a.FI.FI > b.SE.FI){
		return false;
	}
	return true;
}

void sovle(int h, int w){
	vector<vector<char>> mp(h, vector<char>(w));
	vector<pair<P, P>> tate;
	vector<pair<P, P>> yoko;
	int corner = 0;

	REP(i, h){
		REP(j, w){
			cin >> mp[i][j];
		}
	}

	REP(i, h-1){
		REP(j, w-1){
			int cou = getCount(i, j, mp);
			if(cou == 3){
				corner++;
				P aite = searchPairTate(i, j, mp);
				if(aite.FI != -1){
					tate.EB(MP(i, j), MP(aite.FI, aite.SE));
				}
				aite = searchPairYoko(i, j, mp);
				if(aite.FI != -1){
					yoko.EB(MP(i, j), MP(aite.FI, aite.SE));
				}
			}
		}
	}

	vector<vector<int>> v(tate.size() + yoko.size() + 2);
	Dinic dinic(tate.size() + yoko.size() + 2);
	int start = tate.size() + yoko.size();
	int goal = tate.size() + yoko.size() + 1;

	REP(i, tate.size()){
		dinic.add_edge(start, i, 1);
		REP(j, yoko.size()) {
			if(intersect(yoko[j], tate[i])) {
				dinic.add_edge(i, j + tate.size(), 1);
			}
		}
	}
	REP(i, yoko.size()){
		dinic.add_edge(i + tate.size(), goal, 1);
	}

	cout << corner - (tate.size() + yoko.size() - dinic.solve(start, goal)) + 1 << endl;
}

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

	int h, w;
	while(cin >> h >> w,h + w){
		sovle(h, w);
	}

	return 0;
}



Measured memory_bytes: 4060