//#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <atcoder/all>
using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using i128 = __int128_t;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
constexpr char ln = '\n';
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
inline int kthbit(long long x, int k) {return (x>>k)&1;}
inline void print() {cout << "\n";}
template<class T>
inline void print(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
    print();
}
template<class T, class... Args>
inline void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
inline void debug() {cerr << endl;}
template<class T>
inline void debug(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cerr << *itr << " ";
    debug();
}
template<class T, class... Args>
inline void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
#else
#define dump(x) void(0)
inline void debug() {}
template<class T> inline void debug(const vector<T> &v) {}
template<class T, class... Args> inline void debug(const T &x, const Args &... args) {}
#endif
struct Fast_ios {Fast_ios() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);};} fast_ios;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

template<typename TF,typename TC>
struct PrimalDual{
    struct edge{
        int to;
        TF cap;
        TC cost;
        int rev;
        edge(){}
        edge(int to,TF cap,TC cost,int rev):
        to(to),cap(cap),cost(cost),rev(rev){}
    };

    static const TC INF;
    vector<vector<edge>> G;
    vector<TC> h,dist;
    vector<int> prevv,preve;

    PrimalDual(){}
    PrimalDual(int N):G(N),h(N),dist(N),prevv(N),preve(N){}

    void add_edge(int u,int v,TF cap,TC cost) {
        G[u].emplace_back(v,cap,cost,G[v].size());
        G[v].emplace_back(u,0,-cost,G[u].size()-1);
    }

    void dijkstra(int s) {
        struct P {
            TC first;
            int second;
            P(TC first,int second):first(first),second(second){}
            bool operator<(const P&a) const{return a.first<first;}
        };
        priority_queue<P> que;
        fill(dist.begin(),dist.end(),INF);

        dist[s] = 0;
        que.emplace(dist[s],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) continue;
                if(dist[v]+e.cost+h[v]-h[e.to]<dist[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);
                }
            }
        }
    }

    TC flow(int s,int t,TF f,int &ok){
        TC res=0;
        fill(h.begin(),h.end(),0);
        while(f>0){
            dijkstra(s);
            if(dist[t] == INF) {
                ok = 0;
                return res;
            }

            for(int v = 0; v < (int)h.size(); v++)
                if(dist[v]<INF) h[v]=h[v]+dist[v];

            TF d=f;
            for(int v = t; v != s; v = prevv[v])
                d=min(d,G[prevv[v]][preve[v]].cap);

            f-=d;
            res = res + h[t]*d;
            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;
            }
        }
        ok = 1;
        return res;
    }
};
template<typename TF, typename TC>
const TC PrimalDual<TF, TC>::INF = numeric_limits<TC>::max()/2;

template<typename TF,typename TC>
struct NegativeEdge{
	PrimalDual<TF, TC> G;
	vector<TF> fs;
	TC sum;
	int S,T;
	NegativeEdge(){}
	NegativeEdge(int n):G(n+2),fs(n+2,0),sum(0),S(n),T(n+1){}

	void use_edge(int u,int v,TF cap,TC cost){
		fs[u]-=cap;
		fs[v]+=cap;
		sum=sum+cost*cap;
	}

	void add_edge(int u,int v,TF cap,TC cost){
		if(cost<TC(0)){
			use_edge(u,v,cap,cost);
			swap(u,v);
			cost=-cost;
		}
		G.add_edge(u,v,cap,cost);
	}

	TC flow(int &ok){
		TF f=0;
		for(int i=0;i<S;i++){
			if(fs[i]>0){
				f+=fs[i];
				G.add_edge(S,i,+fs[i],TC(0));
			}
			if(fs[i]<0){
				G.add_edge(i,T,-fs[i],TC(0));
			}
		}
		return sum+G.flow(S,T,f,ok);
	}

	TC flow(int ts,int tt,TF tf,int &ok){
		fs[ts]+=tf;
		fs[tt]-=tf;
		return flow(ok);
	}
};

int main() {
    int N,M; cin >> N >> M;
    vector<string> S(N);
    rep(i,N) cin >> S[i];
    NegativeEdge<int, int> G(N*M+2);
    int s = N*M;
    int t = N*M+1;
    int cnt = 0;
    rep(i,N) rep(j,M) {
        if (S[i][j]=='#') continue;
        G.add_edge(i*M+j,t,1,0);
        if (i < N-1 and S[i+1][j]!='#') {
            G.add_edge(i*M+j,(i+1)*M+j,100,-1);
        }
        if (j < M-1 and S[i][j+1]!='#') {
            G.add_edge(i*M+j,i*M+j+1,100,-1);
        }
        if (S[i][j]=='o') {
            G.add_edge(s,i*M+j,1,0);
            cnt++;
        }
    }
	
    int ok = false;
    cout << -G.flow(s,t,cnt,ok) << ln;
}


Measured memory_bytes: 4220