#include using namespace std; int n,S,T; int hd[100005],nxt[800005],c[800005],dy[800005],tot=1; int cur[100005],l[100005]; void addedge(int u,int v,int w){ nxt[++tot]=hd[u],hd[u]=tot; c[tot]=w,dy[tot]=v; } bool getc(){ for(int i=1;i<=n;++i)l[i]=1e9,cur[i]=hd[i]; l[S]=0; queueq; q.emplace(S); while(q.size()){ int x=q.front(); q.pop(); for(int i=hd[x];i;i=nxt[i]){ if(!c[i])continue; int cu=dy[i]; if(l[cu]>l[x]+1){ l[cu]=l[x]+1; q.emplace(cu); } } } return l[T]<1e9; } int ans=0; int dinic(int x,int rl){ if(x==T){ ans+=rl; return rl; } int rr=rl; for(int i=cur[x];i;i=nxt[i]){ cur[x]=i; if(!c[i])continue; int cu=dy[i]; if(l[cu]!=l[x]+1)continue; int zz=dinic(cu,min(rr,c[i])); c[i]-=zz,c[i^1]+=zz; rr-=zz; if(!rr)break; } return rl-rr; } char s[105][105]; #define mk(x,y) (((x)-1)*M+(y)) int mb[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int main(){ int N,M; scanf("%d%d",&N,&M); n=N*M+2,S=n-1,T=n; int bb=0,ww=0; for(int i=1;i<=N;++i){ scanf("%s",s[i]+1); for(int j=1;j<=M;++j)if(s[i][j]!='.'){ if(s[i][j]=='w')addedge(S,mk(i,j),1),addedge(mk(i,j),S,0),++ww; else addedge(mk(i,j),T,1),addedge(T,mk(i,j),0),++bb; } } for(int i=1;i<=N;++i)for(int j=1;j<=M;++j)if(s[i][j]=='w'){ for(int k=0;k<4;++k){ int dx=i+mb[k][0],dy=j+mb[k][1]; if(dx<1||dx>N||dy<1||dy>M||s[dx][dy]!='b')continue; addedge(mk(i,j),mk(dx,dy),1); addedge(mk(dx,dy),mk(i,j),0); } } while(getc())dinic(S,INT_MAX); int an=bb+ww+8*min(bb,ww)+90*ans; printf("%d\n",an); return 0; }