#include <bits/stdc++.h>
using std::cin;
using std::cout;
const int N = 216, forbidden = 0x3f3f3f3f;
namespace Flow {
const int N = 80054, M = N * 4;
struct edge {
  int u, v, f;
  edge(int u0 = 0, int v0 = 0, int f0 = 0) : u(u0), v(v0), f(f0) {}
} e[M];
int V = 2, E = 0, si = 1, ti = 2, flow;
int first[N], next[M];
int dep[N], cur[N], que[N];
inline void addedge(int u, int v, int f) {
  e[++E] = edge(u, v, f), next[E] = first[u], first[u] = E;
  e[++E] = edge(v, u), next[E] = first[v], first[v] = E;
}
bool bfs() {
  int h, t = 1, i, x, y;
  memset(dep, -1, sizeof dep);
  que[0] = si, dep[si] = 0;
  for (h = 0; h < t; ++h) {
    if ((x = que[h]) == ti) return true;
    for (i = first[x]; i; i = next[i])
      if (dep[y = e[i].v] == -1 && e[i].f) que[t++] = y, dep[y] = dep[x] + 1;
  }
  return false;
}
int dfs(int x, int lim) {
  int a, c, f = 0;
  if (x == ti || !lim) return lim;
  for (int &i = cur[x]; i; i = next[i])
    if (dep[e[i].v] == dep[x] + 1 && e[i].f) {
      a = std::min(lim - f, e[i].f);
      c = dfs(e[i].v, a);
      e[i].f -= c, e[(((i - 1) ^ 1) + 1)].f += c;
      if ((f += c) == lim) return f;
    }
  return f;
}
int Dinic() {
  for (flow = 0; bfs(); flow += dfs(si, forbidden))
    memcpy(cur, first, sizeof cur);
  return flow;
}
}  // namespace Flow
int R, C, RC;
char s[N];
inline void True(int v, int c) { Flow::addedge(v, 2, c); }
inline void False(int v, int c) { Flow::addedge(1, v, c); }
inline void TrueFalse(int u, int v, int c) { Flow::addedge(u, v, c); }
inline void FalseTrue(int u, int v, int c) { Flow::addedge(v, u, c); }
int main() {
  int i, j;
  std::ios::sync_with_stdio(false), cin.tie(NULL);
  cin >> R >> C, RC = R * C;
  for (i = 0; i < R; ++i)
    for (cin >> s, j = 0; j < C; ++j) {
      if (s[j] & 1)
        FalseTrue(((i)*C + (j) + 3), ((i)*C + (j) + RC + 3), forbidden),
            TrueFalse(((i)*C + (j) + 3), ((i)*C + (j) + RC + 3), forbidden);
      else
        True(((i)*C + (j) + 3), forbidden),
            False(((i)*C + (j) + RC + 3), forbidden);
      if (j)
        TrueFalse(((i)*C + (j) + 3), ((i)*C + (j - 1) + 3), 1);
      else
        True(((i)*C + (j) + 3), 1);
      if (i)
        FalseTrue(((i)*C + (j) + RC + 3), ((i - 1) * C + (j) + RC + 3), 1);
      else
        False(((i)*C + (j) + RC + 3), 1);
    }
  cout << Flow::Dinic() << '\n';
  return 0;
}
