#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>
#include <atcoder/mincostflow>


using namespace std;
using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


// edit

void solve() {
    int N, M;
    cin >> N >> M;
    vector<vector<char>> S(N, vector<char>(M));
    vector<vector<int>> dist(N * M, vector<int>(N * M, INF));
    auto conv = [&](int h, int w) {
        return h * M + w;
    };

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            cin >> S[i][j];
            if (S[i][j] != '#') {
                int to = conv(i, j);
                dist[to][to] = 0;
            }
        }
    }

    for (int from = 0; from < N * M; ++from) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < M; ++j) {
                if (dist[from][conv(i, j)] != INF) {
                    int cost = dist[from][conv(i, j)];
                    if (i + 1 < N && S[i + 1][j] != '#') {
                        dist[from][conv(i + 1, j)] = cost + 1;
                    }
                    if (j + 1 < M && S[i][j + 1] != '#') {
                        dist[from][conv(i, j + 1)] = cost + 1;
                    }
                }
            }
        }
    }

    ll BIG = (ll) 1e6;

    mcf_graph<ll, ll> mcf(2 * N * M + 2);
    int start = 2 * N * M;
    int term = start + 1;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            if (S[i][j] == 'o') {
                {
                    int to = 2 * conv(i, j);
                    ll cap = 1;
                    ll cost = 0;
                    mcf.add_edge(start, to, cap, cost);
                }
                for (int ni = i; ni < N; ++ni) {
                    for (int nj = j; nj < M; ++nj) {
                        int from = 2 * conv(i, j);
                        int to = 2 * conv(ni, nj) + 1;
                        ll cap = 1;
                        ll cost = dist[conv(i, j)][conv(ni, nj)];
                        if (cost != INF) {
                            ll d_cost = BIG - cost;
                            mcf.add_edge(from, to, cap, d_cost);
                        }
                    }
                }
            }
            {
                int from = 2 * conv(i, j) + 1;
                ll cap = 1;
                ll cost = 0;
                mcf.add_edge(from, term, cap, cost);
            }
        }
    }

    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            if (S[i][j] == 'o') cnt++;
        }
    }
    auto ret = mcf.flow(start, term, cnt);
    ll ans = BIG * cnt - ret.second;
    cout << ans << endl;

//    auto edges = mcf.edges();
//    for (auto e : edges) {
//        if (e.flow >= 1) {
//            cout << e.from << " " << e.to << " " << e.cap << " " << e.flow << " " << e.cost << endl;
//        }
//    }

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 32884