using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static int H;
        static int W;
        static string[] S;
        static bool[,] used;
        static long ans = 0;
        
        //static long mod = 1000000007;
        //static char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (Char)i).ToArray();
        static void Main(string[] args)
        {
            //var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            //var N = long.Parse(Console.ReadLine());
            var HW = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            H  = HW[0];
            W  = HW[1];
            S = new string[H];
            used = new bool[H,W];
            for (int i = 0; i < H; i++)
            {
                S[i] = Console.ReadLine();
            }

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (S[i][j] == '#' && !used[i,j])
                    {
                        WFS(i,j);
                    }
                }
            }

            Console.WriteLine(ans);
           
        }

        static void WFS(int p, int q)
        {
            //Queue<Tuple<int, int>> que1 = new Queue<Tuple<int, int>>();
            //while (que1.Count() > 0)
            //{
                
            //    var tmp1 = que1.Dequeue();
            //    if (!used[tmp1.Item1,tmp1.Item2])
            //    {
                    
            //    }
            //}

            long black = 0;
            long white = 0;
            Queue<Tuple<int, int>> que2 = new Queue<Tuple<int, int>>();
            que2.Enqueue(new Tuple<int, int>(p, q));
            used[p, q] = true;
            black++;
            while (que2.Count() > 0)
            {
                var tmp = que2.Dequeue();
                var k = tmp.Item1;
                var l = tmp.Item2;
                if (k > 0 && S[k-1][l] != S[k][l] && !used[k - 1, l])
                {
                    if(S[k - 1][l] == '#')
                    {
                        black++;
                    }
                    else
                    {
                        white++;
                    }
                    used[k - 1, l] = true;
                    que2.Enqueue(new Tuple<int, int>(k - 1, l));
                }

                if (l > 0 && S[k][l - 1] != S[k][l] && !used[k, l - 1])
                {
                    if (S[k][l - 1] == '#')
                    {
                        black++;
                    }
                    else
                    {
                        white++;
                    }
                    used[k, l - 1] = true;
                    que2.Enqueue(new Tuple<int, int>(k, l - 1));
                }

                if (k < H-1 && S[k + 1][l] != S[k][l] && !used[k + 1, l])
                {
                    if (S[k + 1][l] == '#')
                    {
                        black++;
                    }
                    else
                    {
                        white++;
                    }
                    used[k + 1, l] = true;
                    que2.Enqueue(new Tuple<int, int>(k + 1, l));
                }

                if (l < W-1 && S[k][l + 1] != S[k][l] && !used[k, l + 1])
                {
                    if (S[k][l + 1] == '#')
                    {
                        black++;
                    }
                    else
                    {
                        white++;
                    }
                    used[k, l + 1] = true;
                    que2.Enqueue(new Tuple<int, int>(k, l + 1));
                }
            }
            ans += black * white;
        }
    }
}


Measured memory_bytes: 44724