#include <bits/stdc++.h>
using namespace std;

class Increase {
public:
  int n, flowMax = 1000000;
  vector<map<int, int>> p;
  vector<int> parent;
  vector<int> stack;

  Increase(int n, vector<map<int, int>> &p) : n(n), p(p) { parent.resize(n); }

  int dfs(int id, int from, int flow) {
    if (parent[id] != id)
      return 0;
    stack.push_back(id);
    parent[id] = from;
    if (id == n - 1)
      return flow;
    for (auto &v : p[id])
      if (v.second > 0) {
        int next = dfs(v.first, id, min(flow, v.second));
        if (next > 0)
          return next;
      }
    return 0;
  }

  int solve() {
    int ret = 0, flow;
    for (int i = 0; i < n; i++)
      parent[i] = i;

    while ((flow = dfs(0, -1, flowMax)) > 0) {
      int now = n - 1;
      ret += flow;
      while (parent[now] >= 0) {
        p[parent[now]][now] -= flow;
        p[now][parent[now]] += flow;
        now = parent[now];
      }
      for (auto &v : stack)
        parent[v] = v;
      stack.clear();
    }
    return ret;
  }
};

int main() {
  while (true) {
    int h, w;
    cin >> h >> w;
    if (h == 0)
      break;
    vector<string> mp(h + 2);
    for (int i = 0; i < w + 2; i++) {
      mp[0].push_back('.');
      mp[h + 1].push_back('.');
    }

    for (int i = 0; i < h; i++) {
      string s;
      cin >> s;
      mp[i + 1] = "." + s + ".";
    }

    h += 2;
    w += 2;

    int n = 0;
    vector<vector<int>> used(h, vector<int>(w));
    vector<pair<int, int>> edge;

    // 横
    int yoko = 1;
    for (int i = 0; i < h - 1; i++) {
      for (int j = 0; j < w - 1; j++) {
        // 右
        if (mp[i][j] == '.' && mp[i][j + 1] == '#' && mp[i + 1][j] == '#' &&
            mp[i + 1][j + 1] == '#') {
          n++;
          int ii = i, jj = j + 1;
          while (mp[ii][jj] == '#' && mp[ii + 1][jj] == '#') {
            jj++;
          }
          if (mp[ii][jj] == '#' || mp[ii + 1][jj] == '#') {
            int now = yoko++;
            for (jj -= 1; jj > j; jj--) {
              used[ii][jj] = now;
            }
          }
        } else if (mp[i][j] == '#' && mp[i][j + 1] == '.' &&
                   mp[i + 1][j] == '#' && mp[i + 1][j + 1] == '#') {
          n++;
        } else if (mp[i][j] == '#' && mp[i][j + 1] == '#' &&
                   mp[i + 1][j] == '.' && mp[i + 1][j + 1] == '#') {
          n++;
          int ii = i, jj = j + 1;
          while (mp[ii][jj] == '#' && mp[ii + 1][jj] == '#') {
            jj++;
          }
          if (mp[ii][jj] == '#' || mp[ii + 1][jj] == '#') {
            int now = yoko++;
            for (jj -= 1; jj > j; jj--) {
              used[ii][jj] = now;
            }
          }
        } else if (mp[i][j] == '#' && mp[i][j + 1] == '#' &&
                   mp[i + 1][j] == '#' && mp[i + 1][j + 1] == '.') {
          n++;
        } else if (mp[i][j] == '#' && mp[i][j + 1] == '.' &&
                   mp[i + 1][j] == '.' && mp[i + 1][j + 1] == '.') {
          n++;
        } else if (mp[i][j] == '.' && mp[i][j + 1] == '#' &&
                   mp[i + 1][j] == '.' && mp[i + 1][j + 1] == '.') {
          n++;
        } else if (mp[i][j] == '.' && mp[i][j + 1] == '.' &&
                   mp[i + 1][j] == '#' && mp[i + 1][j + 1] == '.') {
          n++;
        } else if (mp[i][j] == '.' && mp[i][j + 1] == '.' &&
                   mp[i + 1][j] == '.' && mp[i + 1][j + 1] == '#') {
          n++;
        }
      }
    }

    int tate = yoko;
    for (int i = 0; i < h - 1; i++) {
      for (int j = 0; j < w - 1; j++) {
        if (mp[i][j] == '.' && mp[i][j + 1] == '#' && mp[i + 1][j] == '#' &&
            mp[i + 1][j + 1] == '#') {
          int ii = i + 1, jj = j;
          while (mp[ii][jj] == '#' && mp[ii][jj + 1] == '#') {
            ii++;
          }
          if (mp[ii][jj] == '#' || mp[ii][jj + 1] == '#') {
            int now = tate++;
            for (ii -= 1; ii > i; ii--) {
              if (used[ii][jj] > 0)
                edge.emplace_back(used[ii][jj], now);
              if (used[ii][jj + 1] > 0 && used[ii][jj] == 0)
                edge.emplace_back(used[ii][jj + 1], now);
            }
            if (used[ii][jj + 1] > 0)
              edge.emplace_back(used[ii][jj + 1], now);
          }
        } else if (mp[i][j] == '#' && mp[i][j + 1] == '.' &&
                   mp[i + 1][j] == '#' && mp[i + 1][j + 1] == '#') {
          int ii = i + 1, jj = j;
          while (mp[ii][jj] == '#' && mp[ii][jj + 1] == '#') {
            ii++;
          }
          if (mp[ii][jj] == '#' || mp[ii][jj + 1] == '#') {
            int now = tate++;
            for (ii -= 1; ii > i; ii--) {
              if (used[ii][jj] > 0)
                edge.emplace_back(used[ii][jj], now);
              if (used[ii][jj + 1] > 0 && used[ii][jj] == 0)
                edge.emplace_back(used[ii][jj + 1], now);
            }
            if (used[ii][jj] > 0)
              edge.emplace_back(used[ii][jj], now);
          }
        }
      }
    }

    int m = tate + 1;
    // source: 0, sink: m - 1, yoko: [1, yoko), tate: [yoko, tate)
    vector<map<int, int>> p(m);
    for (int i = 0; i < yoko - 1; i++) {
      p[0][i + 1] = 1;
    }
    for (int i = yoko; i < tate; i++) {
      p[i][m - 1] = 1;
    }
    for (auto &v : edge) {
      p[v.first][v.second] = 1;
    }

    Increase g(m, p);
    int flow = g.solve();
    int indep = m - 2 - flow;

    cout << n / 2 - 1 - indep << endl;
  }
  return 0;
}


Measured memory_bytes: 4808