#include<cstdio>
long long a,b,c,h,w,k[]={0,0,-1,1,0,0},i;
char s[405][405];
void d(int x,int y){
  char t;
  ((t=s[x][y])-'#'?a:b)++;
  s[x][y]=0;
  for(int i=0;i<4;++i)if(s[x+k[i]][y+k[i+2]]+t==81)d(x+k[i],y+k[i+2]);
}
int main(){
  scanf("%d%d",&h,&w);
  for(;i<=h;)scanf("%s",s[++i]+1);
  for(;h;--h)for(i=w;i;--i)if(s[h][i])a=b=0,d(h,i),c+=a*b;
  printf("%lld\n",c);
}