#include "bits/stdc++.h"
#include <atcoder/all>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
// using namespace atcoder;

/*
 Primal_Dual
 */
typedef ll PD_Type;
const PD_Type PD_INF = INF;
struct Primal_Dual{
    typedef pair< PD_Type, int > pii;

    struct edge{
        int to, rev;
        PD_Type    cap, cost;
        edge() {}
        edge(int to, PD_Type cap, PD_Type cost, int rev) :to(to), cap(cap), cost(cost), rev(rev) {}
    };
    vector< vector< edge > > graph;
    vector< int > prevv, preve;
    vector< PD_Type > potential, min_cost;
    Primal_Dual(int V) : graph(V) {}

    void add_edge(int from, int to, PD_Type cap, PD_Type cost){
        pos.emplace_back(from,(int)graph[from].size());
        graph[from].push_back(edge(to, cap, cost, (int)graph[to].size()));
        graph[to].push_back(edge(from, 0, -cost, (int)graph[from].size() - 1));
    }

    PD_Type min_cost_flow(int s, int t, int f){
        int V = (int)graph.size();
        PD_Type ret = 0;
        priority_queue< pii, vector< pii >, greater< pii > > que;
        potential.assign(V, 0);
        preve.assign(V, -1);
        prevv.assign(V, -1);

        while (f > 0) {
            min_cost.assign(V, PD_INF);
            que.push(pii(0, s));
            min_cost[s] = 0;

            while (!que.empty()) {
                pii p = que.top();
                que.pop();
                if (min_cost[p.second] < p.first) continue;
                for (int i = 0; i < (int)graph[p.second].size(); i++) {
                    edge &e = graph[p.second][i];
                    PD_Type nextCost = min_cost[p.second] + e.cost + potential[p.second] - potential[e.to];
                    if (e.cap > 0 && min_cost[e.to] > nextCost) {
                        min_cost[e.to] = nextCost;
                        prevv[e.to] = p.second; preve[e.to] = i;
                        que.push(pii(min_cost[e.to], e.to));
                    }
                }
            }
            if (min_cost[t] == PD_INF) return -1;
            for (int v = 0; v < V; v++) potential[v] += min_cost[v];
            PD_Type addflow = f;
            for (int v = t; v != s; v = prevv[v]) {
                addflow = min(addflow, graph[prevv[v]][preve[v]].cap);
            }
            f -= addflow;
            ret += addflow * potential[t];
            for (int v = t; v != s; v = prevv[v]) {
                edge &e = graph[prevv[v]][preve[v]];
                e.cap -= addflow;
                graph[v][e.rev].cap += addflow;
            }
        }
        return ret;
    }

    struct edge_with_flow{
        int from,to;
        PD_Type cap,flow,cost;
        edge_with_flow(){}
        edge_with_flow(int from,int to,PD_Type cap,PD_Type flow,PD_Type cost):from(from),to(to),cap(cap),flow(flow){}
    };
    vector<pii> pos;

    //  有向グラフにのみ適用
    //  各辺を {from,to,cap,flow:実際に流れた流量,コスト}として取り出す
    //  無向グラフで利用する場合は、両方向からadd_(directed)_edgeをする。
    vector<edge_with_flow> edges(){
        vector<edge_with_flow> ret;
        for(int i = 0; i < (int)pos.size(); i++){
            auto e = graph[pos[i].first][pos[i].second];
            auto re = graph[e.to][e.rev];
            ret.emplace_back(pos[i].first, e.to, e.cap + re.cap, re.cap, e.cost);
        }
        return ret;
    }
};

template<class Type>
Type solve(Type res = Type()){

    int N,M; cin >> N >> M;
    
    int S = N*M,T = S + 1;
    Primal_Dual PD(N*M+2);
    
    int cnt = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M;j++){
            char c; cin >> c;
            
            if(c == '#') continue;;
            int id = i*M+j;
            if(c == 'o'){
                cnt++;
                PD.add_edge(S, id, 1, 0);
            }
            if(i+1 < N){
                int nid = (i+1)*M+j;
                PD.add_edge(id, nid, INF, -1);
            }
            if(j+1 < M){
                int nid = i*M + (j+1);
                PD.add_edge(id, nid, INF, -1);
            }
            
            PD.add_edge(id, T, 1, 0);
        }
    }
    
    res = -PD.min_cost_flow(S, T, cnt);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 4232