using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;

namespace AtCoder.C
{
    public class Program
    {
        public static long H { get; private set; }
        public static long W { get; private set; }
        public static bool[,] IsBlack { get; private set; }
        public static bool[,] IsReached { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            (H, W) = Read2Longs();
            IsBlack = new bool[H, W];
            // 到達済みかどうかを管理する
            IsReached = new bool[H, W];
            for (int i = 0; i < H; i++)
            {
                var S = ReadText();
                for (int j = 0; j < S.Length; j++)
                {
                    IsBlack[i, j] = S[j] == '#';
                }
            }

            var count = 0L;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (IsReached[i, j]) continue;
                    IsReached[i, j] = true;
                    var reachable = GetReachableTable(i, j).ToList();
                    count += GetPathCount(reachable);
                }
            }

            return count;
        }

        private static IEnumerable<Point> GetReachableTable(int i, int j)
        {
            var start = new Point(i, j);
            yield return start;

            var queue = new Queue<Point>();
            var next_right = new Point(i + 1, j);
            if (CanBePath(start, next_right)) queue.Enqueue(next_right);
            var next_down = new Point(i, j + 1);
            if (CanBePath(start, next_down)) queue.Enqueue(next_down);

            while (queue.Count > 0)
            {
                var p = queue.Dequeue();
                yield return p;

                var right = new Point(p.H + 1, p.W);
                if (CanBePath(p, right)) queue.Enqueue(right);
                var left = new Point(p.H - 1, p.W);
                if (CanBePath(p, left)) queue.Enqueue(left);
                var down = new Point(p.H, p.W + 1);
                if (CanBePath(p, down)) queue.Enqueue(down);
                var up = new Point(p.H, p.W - 1);
                if (CanBePath(p, up)) queue.Enqueue(up);
            }
        }

        private static bool CanBePath(Point current, Point next)
        {
            if (next.H < 0 || next.H >= H) return false;
            if (next.W < 0 || next.W >= W) return false;
            if (IsBlackPoint(current) == IsBlackPoint(next)) return false;
            if (IsReached[next.H, next.W]) return false;

            IsReached[next.H, next.W] = true;
            return true;
        }

        private static bool IsBlackPoint(Point p)
        {
            return IsBlack[p.H, p.W];
        }
        private static long GetPathCount(List<Point> reachable)
        {
            var black = 0L;
            var white = 0L;
            foreach (var point in reachable)
            {
                if (IsBlackPoint(point))
                {
                    black++;
                }
                else
                {
                    white++;
                }
            }

            return black * white;
        }

        class Point
        {
            public long H { get; set; }
            public long W { get; set; }

            public Point(long h, long w)
            {
                H = h;
                W = w;
            }
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 50288