//2020年4月17日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
template <class T, class... A>
void printd(const T &first, const A &... rest) { cout << fixed << setprecision(15) << first; prints_rest(rest...); }


namespace {
	// printElems(&a[0], &a[n]);　みたいな感じで使う。
	void printElems(const int* begin, const int* end)
	{
		for (const int* p = begin; p != end; ++p) {
			cout << *p << ' ';
		}
		cout << endl;
	}
}

#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<n+1; i++)
#define repr(i,n) for(ll i=n-1; i>=0; i--)
#define repr1(i,n) for(ll i=n; i>0; i--)
#define FOR(i,j,n) for(ll i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(ll i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<ll,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const ll BIG = 1LL<<60;
const string yes = "Yes";
const string no = "No";

//----------------------------------------------

dsu d(200005);
/*pii opm(pii a, pii b) {
    if(a >= b) return b;
	else return a;
}

pii em() {
    return (pii)(mp(1e9,1e9));
}

segtree<pii, opm, em> segmin(200005);

pii opM(pii a, pii b) {
    if(a.F <= b.F) return b;
	else return a;
}


pii eM() {
    return (pii)(mp(-1,-1));
}

segtree<pii, opM, eM> segmax(200005);

*/


string maze[60];
ll dp[60][60];

const ll big = 6000;

int main(){
	int n,m;
	cin >> n >> m;
	rep1(i,n){
		cin >> maze[i];
		maze[i] = "#"+maze[i]+"#";
	}
	maze[0] = "";
	maze[n+1] = "";
	rep(i,60){
		maze[0]+="#";
		maze[n+1]+="#";
	}
	rep(i,60){
		rep(j,50)maze[i]+="#";
	}
	mcf_graph<ll,ll> mcf(n*m*2+2);
	ll s = 0;
	ll t = n*m*2+1;
	ll cnt = 0;
	rep1(si,n){
		rep1(sj,m){
			if(maze[si][sj] == '#')continue;
			if(maze[si][sj] == 'o'){
				mcf.add_edge(s,(si-1)*m+sj,1,0);
				cnt++;
			}

			rep(i,60)rep(j,60) dp[i][j] = -1;
			dp[si][sj] = 0;
			rep1(i,59)rep1(j,59){
				if(maze[i][j] == '#') continue;
				if(dp[i-1][j]!=-1){
					dp[i][j] = max(dp[i][j],dp[i-1][j]+1);
				}
				if(dp[i][j-1]!=-1){
					dp[i][j] = max(dp[i][j],dp[i][j-1]+1);
				}
			}
			rep(i,60)rep(j,60){
				if(dp[i][j]!=-1){
					mcf.add_edge((si-1)*m+sj,n*m+(i-1)*m+j,1,big-dp[i][j]); //ヤバかったらここのコストを変える
				}
			}
		}
	}
	for(int i=1;i<n*m+1;i++){
		mcf.add_edge(n*m+i,t,1,0);
	}

	pll ans = mcf.flow(s,t,cnt);
	prints(cnt*big-ans.S);









/*	int n,q;
	cin >> n >> q;
	rep(i,n){
		ll a;
		cin >> a;
		f.add(i,a);
	}
	vll ans;
	rep(i,q){
		ll t,u,v;
		cin >> t >> u >> v;
		if(t == 0){
			f.add(u,v);
		}
		else{
			ans.push_back(f.sum(u,v));
		}
	}
	for(ll x : ans){
		prints(x);
	}



	ll t;
	cin >> t;
	vll ans;
	rep(_,t){
		ll n,m,a,b;
		cin >> n >> m >> a >> b;
		ans.push_back(floor_sum(n,m,a,b));
	}

	for(ll x : ans){
		prints(x);
	}

*/





	return 0;
}




Measured memory_bytes: 111076