#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const int MAX = 400;
char lis[MAX][MAX];
int color[MAX][MAX] = {};

int h,w;

struct Point{
    int x,y;
};

ll bfs(Point p){
    ll nw = 0;
    ll nb = 0;
    queue <Point> q;
    q.push(p);
    color[p.x][p.y] = 1;
    while(!q.empty()){
        Point u = q.front();
        q.pop();
        if(lis[u.x][u.y] == '.'){
            nw++;
            if(u.x != 0){
                if(lis[u.x-1][u.y] == '#' and color[u.x-1][u.y] == 0){
                    Point post;
                    post.x = u.x - 1;
                    post.y = u.y;
                    q.push(post);
                    color[post.x][post.y] = 1;
                }
            }
            if(u.y != 0){
                if(lis[u.x][u.y-1] == '#' and color[u.x][u.y-1] == 0){
                    Point post;
                    post.x = u.x;
                    post.y = u.y - 1;
                    q.push(post);
                    color[post.x][post.y] = 1;
                }
            }
            if(u.x != h-1){
                if(lis[u.x+1][u.y] == '#' and color[u.x+1][u.y] == 0){
                    Point post;
                    post.x = u.x + 1;
                    post.y = u.y;
                    q.push(post);
                    color[post.x][post.y] = 1;
                }
            }
            if(u.y != w-1){
                if(lis[u.x][u.y+1] == '#' and color[u.x][u.y+1] == 0){
                    Point post;
                    post.x = u.x;
                    post.y = u.y+1;
                    q.push(post);
                    color[post.x][post.y] = 1;
                }
            }
        }else{
            nb++;
            if(u.x != 0){
                if(lis[u.x-1][u.y] == '.' and color[u.x-1][u.y] == 0){
                    Point post;
                    post.x = u.x - 1;
                    post.y = u.y;
                    q.push(post);
                    color[post.x][post.y] = 1;
                }
            }
            if(u.y != 0){
                if(lis[u.x][u.y-1] == '.' and color[u.x][u.y-1] == 0){
                    Point post;
                    post.x = u.x;
                    post.y = u.y - 1;
                    q.push(post);
                    color[post.x][post.y] = 1;
                }
            }
            if(u.x != h-1){
                if(lis[u.x+1][u.y] == '.' and color[u.x+1][u.y] == 0){
                    Point post;
                    post.x = u.x + 1;
                    post.y = u.y;
                    q.push(post);
                    color[post.x][post.y] = 1;
                }
            }
            if(u.y != w-1){
                if(lis[u.x][u.y+1] == '.' and color[u.x][u.y+1] == 0){
                    Point post;
                    post.x = u.x;
                    post.y = u.y+1;
                    q.push(post);
                    color[post.x][post.y] = 1;
                }
            }

        }
    }
    return nb * nw;
}


int main() {
   
    cin >> h >> w;

    for (int i=0;i<h;i++){
        string s;
        cin >> s;
        for (int j=0;j<w;j++){
            lis[i][j] = s[j];
        }
    }
    ll ans = 0;
    for (int i=0;i<h;i++){
        for (int j=0;j<w;j++){
            if(color[i][j] == 0){
                Point p;
                p.x = i;
                p.y = j;
                ans += bfs(p);
            }
        }
    }
    cout << ans << endl;

//    for (int i=0;i<h;i++){
//        if(i){
//            cout << endl;
//        }
//        for (int j=0;j<w;j++){
//            cout << lis[i][j];
//        }
//    }

}




Measured memory_bytes: 1024