#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define bits(x) bitset<22>(x)
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

const int inf = 1e9;
const int nmax1 = 110;
const int nmax2 = 50*50+10;
///===========================================  template  =======================================================

char grid[55][55];
int vis[55][55];

int matrix[nmax1][nmax2];
int U[nmax2], V[nmax2], minV[nmax2];
bool used[nmax2];
int match[nmax2], way[nmax2];

int Hungarian(int x, int y){
//    fill(U, U+x+1, 0);
//    fill(V, V+y+1, 0);
//    fill(match, match+y+1, 0);
//    fill(way, way+y+1, 0);

    for(int i = 1; i<=x; i++){
        match[0] = i;
        int lastJ = 0;
        fill(minV, minV+y+1, inf);
        fill(used, used+y+1, false);
        do{
            used[lastJ] = true;
            int lastI = match[lastJ], delta = inf, nextJ;
            for(int j = 1; j<=y; j++){
                if(used[j]) continue;
                int diffCost = matrix[lastI][j] - U[lastI] - V[j];
                if(diffCost < minV[j]) minV[j] = diffCost, way[j] = lastJ;
                if(minV[j] < delta) delta = minV[j], nextJ = j;
            }
            for(int j = 0; j<=y; j++){
                if(used[j]) U[match[j]] += delta, V[j] -= delta;
                else        minV[j] -= delta;
            }
            lastJ = nextJ;
        } while(match[lastJ] != 0);
        do{
            int prevJ = way[lastJ];
            match[lastJ] = match[prevJ];
            lastJ = prevJ;
        } while(lastJ != 0);
    }
    return -V[0];
}

int n, m;
#define valid(x, y) (unsigned(x) < n && unsigned(y) < m)

void bfs(int x, int y, int pcnt){

//    debug(), dbg(x), dbg(y), dbg(pcnt);

    for(int i = 1; i<=n*m; i++){
        matrix[pcnt][i] = 1e6;
    }

    queue<int> qX, qY;
    qX.push(x);
    qY.push(y);
    matrix[pcnt][x*m+y+1] = 0;

    while(!qX.empty()){
        x = qX.front(); y = qY.front();
        qX.pop(); qY.pop();

//        debug(), dbg(x), dbg(y);
        int id = x*m + y + 1;

        if(valid(x+1, y) && grid[x+1][y] != '#'){
            int nid = (x+1)*m + y + 1;
            if(matrix[pcnt][nid] == 1e6){
                matrix[pcnt][nid] = matrix[pcnt][id]-1;
                qX.push(x+1);
                qY.push(y);
            }
        }

        if(valid(x, y+1) && grid[x][y+1] != '#'){
            int nid = x*m + (y+1) + 1;
            if(matrix[pcnt][nid] == 1e6){
                matrix[pcnt][nid] = matrix[pcnt][id]-1;
                qX.push(x);
                qY.push(y+1);
            }
        }
    }
}

int main(){
    FASTIO;

    cin>>n>>m;

    for(int i = 0; i<n; i++){
        cin>>grid[i];
    }

    int pieces = 0;
    for(int i = 0; i<n; i++){
        for(int j = 0;j<m; j++){
            if(grid[i][j] == 'o'){
                pieces++;
                bfs(i, j, pieces);
            }
        }
    }

//
//    for(int i = 1; i<=pieces; i++){
//        debug(), dbg(i), dbg(range(matrix[i]+1, matrix[i]+n*m+1));
//    }

    int ans = -Hungarian(pieces, n*m);
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4700