#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

void place(int x, int y, vector<vector<int>>& P, vector<vector<int>>& flag, int tmp){

  //printf("place x:%d, y:%d\n", x, y);
  if(flag[x][y]==0) return;

  flag[x][y] = tmp;

  long int H, W;
  H = P.size();
  W = P[0].size();

  if(x>0){
    if(P[x-1][y]==1-P[x][y] && flag[x-1][y]!=tmp) place(x-1, y, P, flag, tmp);
  }
  if(x<H-1){
    if(P[x+1][y]==1-P[x][y] && flag[x+1][y]!=tmp) place(x+1, y, P, flag, tmp);
  }
  if(y>0){
    if(P[x][y-1]==1-P[x][y] && flag[x][y-1]!=tmp) place(x, y-1, P, flag, tmp);
  }
  if(y<W-1){
    if(P[x][y+1]==1-P[x][y] && flag[x][y+1]!=tmp) place(x, y+1, P, flag, tmp);
  }

  return;
}

int count(int x, int y, vector<vector<int>>& P, vector<vector<int>>& flag){
  long int ans=0;

  //printf("count : %d, %d\n", x, y);

  if(flag[x][y]!=0) return ans;

  long int H, W;
  H = P.size();
  W = P[0].size();

  if(P[x][y]==1) ans+=1;

  flag[x][y]=1;

  //printf("P = %d\n", P[x][y]);

  if(x>0){
    if(P[x-1][y]==1-P[x][y] && flag[x-1][y]==0) ans+=count(x-1, y, P, flag);
  }
  if(x<H-1){
    if(P[x+1][y]==1-P[x][y] && flag[x+1][y]==0) ans+=count(x+1, y, P, flag);
  }
  if(y>0){
    if(P[x][y-1]==1-P[x][y] && flag[x][y-1]==0) ans+=count(x, y-1, P, flag);
  }
  if(y<W-1){
    if(P[x][y+1]==1-P[x][y] && flag[x][y+1]==0) ans+=count(x, y+1, P, flag);
  }

  return ans;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  long int H, W;
  cin >> H;
  cin >> W;
  vector<vector<int>> P;
  P.resize(H);
  for(int i=0; i<H; ++i){
    P[i].resize(W);
    string tmp;
    cin >> tmp;
    for(int j=0; j<W; ++j){
      if(tmp[j]=='#') P[i][j]=0;
      else P[i][j]=1;
    }
  }

  long int ans=0;

  //printf("hoge\n");

  vector<vector<int>> flag(H, vector<int>(W, 0));

  for(int i=0; i<H; ++i){
    for(int j=0; j<W; ++j){
      //printf("%d %d\n", i, j);
      if(P[i][j]==1) continue;
      if(flag[i][j] != 0){
        ans += flag[i][j];
       continue;
      }
      //printf("count start\n");
      long int tmp = count(i, j, P, flag);
      //printf("count end\n");
      ans += tmp;
      place(i, j, P, flag, tmp);
      //printf("ans = %d\n", ans);
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 23936