using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const int MOD = 1000000007;
        private enum Color
        {
            B,
            W,
        }
        private struct Coordinate
        {
            public int x;
            public int y;
            public Coordinate(int x, int y)
            {
                this.x
                     = x;
                this.y = y;
            }
        }
        private static readonly int[] offsetX = { 0, -1, 1, 0 };// 2468方向
        private static readonly int[] offsetY = { 1, 0, 0, -1 };
        static void Solve()
        {
            var hw = ReadAndParseIntArr();
            int h = hw[0];
            int w = hw[1];
            var color = new Color[h, w];
            for (int i = 0; i < h; ++i)
            {
                var s = Console.ReadLine();
                for (int x = 0; x < w; ++x)
                {
                    color[i, x] = s[x] == '#' ? Color.B : Color.W;
                }
            }
            long ans = 0;
            var queue = new Queue<Coordinate>();
            var dfsColor = new int[h, w];

            var used = new bool[h, w];
            for (int x = 0; x < w; ++x)
            {
                for (int y = 0; y < h; ++y)
                {
                    if (used[y, x]) { continue; }

                    used[y, x] = true;
                    // bfs
                    long totalB = 0;
                    long totalW = 0;
                    queue.Clear();
                    queue.Enqueue(new Coordinate(x, y));
                    if (color[y, x] == Color.B) { totalB++; }
                    else { totalW++; }

                    
                    while (queue.Count >= 1)
                    {
                        var u = queue.Peek();
                        queue.Dequeue();
                        for(int d = 0;d<4;++d)
                        {
                            var v = new Coordinate(u.x + offsetX[d], u.y + offsetY[d]);
                            if(!IsConnected(u, v, w, h, color)){ continue; }
                            if(used[v.y, v.x]) { continue; }
                            used[v.y, v.x] = true;
                            if (color[v.y, v.x] == Color.B) { totalB++; }
                            else { totalW++; }

                            queue.Enqueue(v);
                        }
                     
                    }

                    ans += totalB * totalW;
                }
            }
            Console.WriteLine(ans);
        }
        private static bool IsConnected(Coordinate src, Coordinate dst, int w, int h, Color[,] table)
        {
            if (dst.x < 0 || w <= dst.x) { return false; }
            if (dst.y < 0 || h <= dst.y) { return false; }
            if (table[src.y, src.x] == table[dst.y, dst.x]) { return false; }
            return true;
        }
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 13396