#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
using namespace std;
typedef pair<int, int>P;

int H, W;
int initialState[12][2];
vector<int>nexts;
vector<int>nextsScore;
map<int, int>dp[12];

void makeInitialState(){
	for (int y = 0; y < H; y++){
		for (int x = 0; x < W; x++){
			char c;
			cin >> c;
			if (c == '.'){
				initialState[y][0] |= (1 << x);
				initialState[y][1] |= (1 << x);
			}
			else if (c == '#'){
				initialState[y][1] |= (1 << x);
			}
		}
	}
}

void makeNexts(){
	for (int i = 0; i < (1 << W); i++){
		int cnt = 0;
		bool pre = 0;
		bool flg = 1;
		for (int j = 0; j < W; j++){
			bool cur = (i & (1 << j) ? 1 : 0);
			if (!cur)cnt++;
			if (pre & cur)flg = 0;
			pre = cur;
		}
		if (flg){
			nexts.push_back(i);
			nextsScore.push_back(cnt);
		}
	}
}

string str(int num){
	string res = "(";
	vector<int>from(W, 0);
	for (int x = 0, idx = W; x < W; x++){
		if ((num & (1 << x))&((1 << W) - 1)) {
			res += ".";
			continue;
		}
		bool readFlg = 0;
		if (x == 0)readFlg = 1;
		else if (from[x - 1] == 0)readFlg = 1;
		if (readFlg){
			for (int i = 0; i < 3; i++){
				if (num & (1 << (idx + i))){
					from[x] += (1 << i);
				}
			}
			idx += 3;
		}
		else{
			from[x] = from[x - 1];
		}
		char c = '0';
		c += from[x];
		res += c;
	}
	res += ")";
	return res;
}

bool sepCheck(int num){
	vector<int>from(W, 0);
	for (int x = 0, idx = W; x < W; x++){
		if ((num & (1 << x))&((1 << W) - 1)) {
			continue;
		}
		bool readFlg = 0;
		if (x == 0)readFlg = 1;
		else if (from[x - 1] == 0)readFlg = 1;
		if (readFlg){
			for (int i = 0; i < 3; i++){
				if (num & (1 << (idx + i))){
					from[x] += (1 << i);
				}
			}
			idx += 3;
		}
		else{
			from[x] = from[x - 1];
		}
		if (from[x]>1)return 0;
	}
	return 1;
}

int calcNext(int pre, int cur){
	if (pre&cur)return -1;
	vector<int>path[50];
	vector<int>flg(50, 0);
	vector<int>from(W, 0);
	for (int x = 0, idx = W; x < W; x++){
		if (pre & (1 << x))continue;
		bool readFlg = 0;
		if (x == 0)readFlg = 1;
		else if (from[x - 1] == 0)readFlg = 1;
		if (readFlg && pre!=0){
			for (int i = 0; i < 3; i++){
				if (pre & (1 << (idx + i))){
					from[x] += (1 << i);

				}
			}
			flg[from[x]] = -1;
			idx += 3;
			path[x + 12].push_back(from[x]);
			path[from[x]].push_back(x + 12);
			
		}
		else{
			from[x] = from[x - 1];
		}
		if (x){
			if (from[x - 1] == from[x] && pre != 0){
				path[x + 12].push_back(x + 11);
				path[x + 11].push_back(x + 12);
			}
		}
	}

	for (int x = 0; x < W; x++){
		if (cur & (1 << x))continue;
		flg[x + 24] = -1;
		if (x){
			if (flg[x + 23] == -1){
				path[x + 24].push_back(x + 23);
				path[x + 23].push_back(x + 24);
			}
		}
		if (!(pre & (1 << x))){
			path[x + 24].push_back(x + 12);
			path[x + 12].push_back(x + 24);
		}
	}
	for (int x = 0, tmp = 0; x < W; x++){
		if (flg[x + 24] != -1)continue;
		tmp++;
		stack<P>S;
		S.push(P(x + 24, 0));
		while (!S.empty()){
			int p = S.top().first;
			int f = S.top().second;
			S.pop();
			if (flg[p] > 0)return -1;
			flg[p] = tmp;
			for (int i = 0; i < path[p].size(); i++){
				if (path[p][i] == f)continue;
				S.push(P(path[p][i], p));
			}
		}
	}
	for (int i = 0; i < W; i++){
		if (flg[i] == -1)return -1;
	}
	for (int x = 0, idx = W; x < W; x++){
		if (flg[x + 24] <= 0)continue;
		bool writeFlg = 0;
		if (x == 0)writeFlg = 1;
		else if (flg[x + 24] != flg[x + 23])writeFlg = 1;
		if (writeFlg){
			int tmp = 0;
			for (int i = 0; i < 3; i++){
				if (flg[x + 24] & (1 << i)){
					cur |= (1 << (idx + i));
				}
			}
			idx += 3;
		}
	}
	return cur;
}

int main(){
	//map<int, int>def[12];
	cin >> H >> W;
	makeInitialState();
	makeNexts();
	dp[0][0] = 0;
	for (int y = 0; y < H; y++){
		//cout << "y:" << y << endl;
		for (std::map<int, int>::iterator it = dp[y].begin(); it != dp[y].end(); it++){
			//cout <<str((*it).first) << "," << (*it).second << endl;
			for (int i = 0; i < nexts.size(); i++){
				if (initialState[y][0] ^ (initialState[y][1] & nexts[i]))continue;
				int next = calcNext((*it).first, nexts[i]);
				if (next < 0)continue;
				//cout << " -> " << str(next) << "," << dp[y + 1][next] << endl;
				if (dp[y + 1][next] < (*it).second + nextsScore[i]){
					//def[y + 1][next] = (*it).first;
					dp[y + 1][next] = (*it).second + nextsScore[i];
				}
			}
		}
	}
	int unko;
	int ans = -1;
	for (std::map<int, int>::iterator it = dp[H].begin(); it != dp[H].end(); it++){
		if (sepCheck((*it).first)){
			if (ans < (*it).second){
				ans = (*it).second;
				unko = (*it).first;
			}
		}
	}
	cout << ans << endl;
	/*
	stack<string>S;
	for (int y = H;unko;y--){
		S.push(str(unko));
		unko = def[y][unko];
	}
	while (!S.empty()){
		cout << S.top() << endl;
		S.pop();
	}
	*/
	return 0;
}


Measured memory_bytes: 4028