#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd   ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm   ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs   ( llong n )          { return ( n < 0 ) ? -n : n; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}
    #define int llong

namespace Rlyeh {

    int h, w;
    char mas[512][512];
    signed uf[512][512];

    int bfs(int sy, int sx, int id) {
        int kuro = 0;
        int shiro = 0;
        Queue<Pii> que;
        que.push(Pii(sy, sx));
        while ( !que.empty() ) {
            Pii now = que.front();
            int x = now.second;
            int y = now.first;
            que.pop();
            for ( int i = 0; i < 4; i++ ) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if ( isMovable(nx, ny, w, h) && mas[ny][nx] != mas[y][x] ) {
                    if ( uf[ny][nx] == 0 ) {
                        if ( mas[ny][nx] == '.' ) shiro++;
                        else kuro++;
                        que.push(Pii(ny, nx));
                        uf[ny][nx] = id;
                    }
                }
            }
        }
        return kuro*shiro;
    }

    signed call_of_Cthulhu( signed datum ) {

        read h >> w;
        for ( int i = 0; i < h; i++ ) {
            read mas[i];
        }

        int cnt = 0;
        int ans = 0;
        for ( int i = 0; i < h; i++ ) {
            for ( int j = 0; j < w; j++ ) {
                if ( uf[i][j] == 0 && mas[i][j] == '#' ) {
                    ans +=bfs(i, j, ++cnt);
                }
            }
        }

        echo ans fin;


        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 1280