#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
template <class T> struct LHeap{
  int*hp;
  int*place;
  int size;
  T*val;
  void malloc(int N){
    hp = (int*)std::malloc(N*sizeof(int));
    place=(int*)std::malloc(N*sizeof(int));
    val=(T*)std::malloc(N*sizeof(T));
  }
  void walloc(int N, void **mem=&wmem){
    walloc1d(&hp, N, mem);
    walloc1d(&place, N, mem);
    walloc1d(&val, N, mem);
  }
  void free(){
    std::free(hp);
    std::free(place);
    std::free(val);
  }
  void init(int N){
    int i;
    size=0;
    for(i=(0);i<(N);i++){
      place[i]=-1;
    }
  }
  void up(int n){
    int m;
    while(n){
      m=(n-1)/2;
      if(val[hp[m]]<=val[hp[n]]){
        break;
      }
      swap(hp[m],hp[n]);
      swap(place[hp[m]],place[hp[n]]);
      n=m;
    }
  }
  void down(int n){
    int m;
    for(;;){
      m=2*n+1;
      if(m>=size){
        break;
      }
      if(m+1<size&&val[hp[m]]>val[hp[m+1]]){
        m++;
      }
      if(val[hp[m]]>=val[hp[n]]){
        break;
      }
      swap(hp[m],hp[n]);
      swap(place[hp[m]],place[hp[n]]);
      n=m;
    }
  }
  void change(int n, T v){
    T f = val[n];
    val[n] = v;
    if(place[n]==-1){
      place[n] = size;
      hp[size++] = n;
      up(place[n]);
    }
    else{
      if(f < v){
        down(place[n]);
      }
      else if(f > v){
        up(place[n]);
      }
    }
  }
  int pop(void){
    int res = hp[0];
    place[res] = -1;
    size--;
    if(size){
      hp[0]=hp[size];
      place[hp[0]]=0;
      down(0);
    }
    return res;
  }
}
;
template<class FT, class CT> struct minCostFlow{
  int node;
  int*es;
  int*emem;
  int**edge;
  int**rev;
  FT**flow;
  FT eps;
  CT**cost;
  LHeap<CT> hp;
  char*reached;
  FT*cur_flow;
  CT*cur_cost;
  int*back_edge;
  void malloc(int N){
    int i;
    es = (int*)std::malloc(N*sizeof(int));
    emem = (int*)std::malloc(N*sizeof(int));
    edge = (int**)std::malloc(N*sizeof(int*));
    rev = (int**)std::malloc(N*sizeof(int*));
    flow = (FT**)std::malloc(N*sizeof(FT*));
    cost = (CT**)std::malloc(N*sizeof(CT*));
    for(i=(0);i<(N);i++){
      emem[i] = 0;
      edge[i] = rev[i] = NULL;
      flow[i] = NULL;
      cost[i] = NULL;
    }
    hp.malloc(N);
    reached = (char*)std::malloc(N*sizeof(char));
    cur_flow = (FT*)std::malloc(N*sizeof(FT));
    cur_cost = (CT*)std::malloc(N*sizeof(CT));
    back_edge = (int*)std::malloc(N*sizeof(int));
    node = N;
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    eps = (FT)1e-9;
  }
  void init(int N){
    int i;
    node = N;
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    eps = (FT)1e-9;
  }
  void memoryExpand(int i, int sz){
    if(sz <= emem[i]){
      return;
    }
    sz =max_L(max_L(sz, 3), 2*emem[i]);
    emem[i] = sz;
    edge[i] = (int*)realloc(edge[i], sz*sizeof(int));
    rev[i] = (int*)realloc(rev[i], sz*sizeof(int));
    flow[i] = (FT*)realloc(flow[i], sz*sizeof(FT));
    cost[i] = (CT*)realloc(cost[i], sz*sizeof(CT));
  }
  void addEdge(int n1, int n2, FT f, CT c){
    int s1 = es[n1]++;
    int s2 = es[n2]++;
    if(s1 >= emem[n1]){
      memoryExpand(n1, es[n1]);
    }
    if(s2 >= emem[n2]){
      memoryExpand(n2, es[n2]);
    }
    edge[n1][s1] = n2;
    edge[n2][s2] = n1;
    rev[n1][s1]  = s2;
    rev[n2][s2]  = s1;
    flow[n1][s1] = f;
    flow[n2][s2] = 0;
    cost[n1][s1] = c;
    cost[n2][s2] = -c;
  }
  template<class FTS, class CTS> void solve(int st, int ed, FTS &fres, CTS &cres, FT flim = -1){
    int i;
    int j;
    int k;
    FT f;
    fres = 0;
    cres = 0;
    for(;;){
      hp.init(node);
      for(i=(0);i<(node);i++){
        reached[i] = 0;
      }
      reached[st] = 1;
      cur_cost[st] = 0;
      hp.change(st, cur_cost[st]);
      while(hp.size){
        i = hp.pop();
        for(j=(0);j<(es[i]);j++){
          if(flow[i][j] <= eps){
            continue;
          }
          k = edge[i][j];
          if(reached[k]==0 || cur_cost[k] > cur_cost[i]+cost[i][j]+eps){
            reached[k] = 1;
            cur_cost[k] = cur_cost[i] + cost[i][j];
            cur_flow[k] = flow[i][j];
            if(i!=st){
              chmin(cur_flow[k], cur_flow[i]);
            }
            back_edge[k] = rev[i][j];
            hp.change(k, cur_cost[k]);
          }
        }
      }
      if(reached[ed]==0){
        break;
      }
      if(flim==-2 && cur_cost[ed] < 0){
        break;
      }
      f = cur_flow[ed];
      if(flim != -1 && flim != -2){
        chmin(f, flim);
      }
      if(f < eps){
        break;
      }
      fres += f;
      cres += f * cur_cost[ed];
      i = ed;
      while(i != st){
        j = back_edge[i];
        k = edge[i][j];
        flow[i][j] += f;
        flow[k][rev[i][j]] -= f;
        i = k;
      }
    }
  }
}
;
struct dimcomp2{
  int B;
  dimcomp2(){
  }
  dimcomp2(int b){
    B = b;
  }
  dimcomp2(int a, int b){
    B = b;
  }
  inline void set(int b){
    B = b;
  }
  inline void set(int a, int b){
    B = b;
  }
  inline int mask(int a, int b){
    return a * B + b;
  }
  inline int operator()(int a, int b){
    return a * B + b;
  }
  inline void para(int mask, int &a, int &b){
    a = mask / B;
    b = mask % B;
  }
  inline void operator()(int mask, int &a, int &b){
    a = mask / B;
    b = mask % B;
  }
}
;
int N;
int M;
char S[50][52];
int main(){
  int i;
  wmem = memarr;
  int node;
  int st;
  int ed;
  int f;
  int c;
  dimcomp2 dm;
  minCostFlow<int,int> flow;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(S[Lj4PdHRW]);
    }
  }
  node = N*M;
  st = node++;
  ed = node++;
  flow.malloc(node);
  flow.init(node);
  dm.set(N,M);
  for(i=(0);i<(N);i++){
    int j;
    for(j=(0);j<(M);j++){
      if(i+1 < N && S[i][j]!='#' && S[i+1][j]!='#'){
        flow.addEdge(dm(i,j), dm(i+1,j), 1073709056, -1);
      }
      if(j+1 < M && S[i][j]!='#' && S[i][j+1]!='#'){
        flow.addEdge(dm(i,j), dm(i,j+1), 1073709056, -1);
      }
    }
  }
  for(i=(0);i<(N);i++){
    int j;
    for(j=(0);j<(M);j++){
      if(S[i][j]=='o'){
        flow.addEdge(st,dm(i,j),1,0);
      }
    }
  }
  for(i=(0);i<(N);i++){
    int j;
    for(j=(0);j<(M);j++){
      if(S[i][j]!='#'){
        flow.addEdge(dm(i,j),ed,1,0);
      }
    }
  }
  flow.solve(st, ed, f, c);
  wt_L(-c);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200920-1

// --- original code ---
// int N, M;
// char S[50][52];
// {
//   int node, st, ed;
//   int f, c;
//   dimcomp2 dm;
//   minCostFlow<int,int> flow;
// 
//   rd(N,M,S(N));
//   node = N*M;
//   st = node++;
//   ed = node++;
//   flow.malloc(node);
//   flow.init(node);
//   dm.set(N,M);
// 
//   rep(i,N) rep(j,M){
//     if(i+1 < N && S[i][j]!='#' && S[i+1][j]!='#') flow.addEdge(dm(i,j), dm(i+1,j), int_inf, -1);
//     if(j+1 < M && S[i][j]!='#' && S[i][j+1]!='#') flow.addEdge(dm(i,j), dm(i,j+1), int_inf, -1);
//   }
//   rep(i,N) rep(j,M) if(S[i][j]=='o') flow.addEdge(st,dm(i,j),1,0);
//   rep(i,N) rep(j,M) if(S[i][j]!='#') flow.addEdge(dm(i,j),ed,1,0);
// 
//   flow.solve(st, ed, f, c);
//   wt(-c);
// }


Measured memory_bytes: 4100