//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

template<class T>
struct MinCostFlow {
  struct edge {
    int to, cap;
    T cost;
    int rev;
  };
  using P = pair<T, int>;
  int V;
  vector<vector<edge>> G;
  vector<T> h, dist;
  vector<int> prevv, preve;
  const T INF;
  //INF*Fがオーバーフローしない　かつ　costより十分に大きい
  MinCostFlow(int n, T INF_):V(n), G(n), h(n), dist(n), prevv(n), preve(n), INF(INF_) {}

  inline void add(int from, int to, int cap, T cost) {
    G[from].emplace_back((edge){to, cap, cost, (int)G[to].size()});
    G[to].emplace_back((edge){from, 0, -cost, (int)G[from].size()-1});
  }
  //最小費用流//無理な時は-1
  T min_cost_flow(const int s, const int t, int f) {
    T res = 0;
    while(f > 0) {
      priority_queue<P, vector<P>, greater<P>> que;
      fill(dist.begin(), dist.end(), INF);
      dist[s] = 0;
      que.emplace(0, s);
      while(!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;
        for(int i = 0; i < (int)G[v].size(); i++) {
          edge &e = G[v][i];
          if(e.cap > 0 and dist[e.to] > dist[v]+e.cost+h[v]-h[e.to]) {
            dist[e.to] = dist[v]+e.cost+h[v]-h[e.to];
            prevv[e.to] = v;
            preve[e.to] = i;
            que.emplace(dist[e.to], e.to);
          }
        }
      }
      if(dist[t] == INF) return -1;
      for(int v = 0; v < V; v++) h[v] += dist[v];

      int d = f;
      for(int v = t; v != s; v = prevv[v]) d = min(d, G[prevv[v]][preve[v]].cap);
      f -= d;
      res += d*h[t];
      for(int v = t; v != s; v = prevv[v]) {
        edge &e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }
    return res;
  }
};

#define N 60

//head

int n, m;
string ss[N];
int u;
int ans;

inline int num(int i, int j) {return i*m+j;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  rep(i, n) cin >> ss[i];
  rep(i, n) rep(j, m) if(ss[i][j] == 'o') u++;
  MinCostFlow<int> mcf(n*m+4, INF/10);
  const int s = n*m, t = s+1, S = s+2, T = S+1;
  rep(i, n) rep(j, m-1) if(ss[i][j] != '#' and ss[i][j+1] != '#') {
    mcf.add(num(i, j), T, 100, 0);
    mcf.add(S, num(i, j+1), 100, 0);
    mcf.add(num(i, j+1), num(i, j), 100, 1);
    ans += 100;
  }
  rep(i, n-1) rep(j, m) if(ss[i][j] != '#' and ss[i+1][j] != '#') {
    mcf.add(num(i, j), T, 100, 0);
    mcf.add(S, num(i+1, j), 100, 0);
    mcf.add(num(i+1, j), num(i, j), 100, 1);
    ans += 100;
  }
  mcf.add(S, s, u, 0);
  mcf.add(t, T, u, 0);
  rep(i, n) rep(j, m) if(ss[i][j] == 'o') mcf.add(s, num(i, j), 1, 0);
  rep(i, n) rep(j, m) if(ss[i][j] != '#') mcf.add(num(i, j), t, 1, 0);
  cout << ans-mcf.min_cost_flow(S, T, u+ans) << endl;
}

Measured memory_bytes: 4452