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

public struct Point
{
    public int X;
    public int Y;

    public Point(Point p)
    {
        X = p.X;
        Y = p.Y;
    }

    public Point(int x, int y)
    {
        X = x;
        Y = y;
    }

    public static bool operator ==(Point a, Point b)
    {
        return (a.X == b.X && a.Y == b.Y);
    }

    public static bool operator !=(Point a, Point b)
    {
        return !(a == b);
    }

    //objと自分自身が等価のときはtrueを返す
    public override bool Equals(object obj)
    {
        if (!(obj is Point))
        {
            return false;
        }

        Point p = (Point)obj;
        return (X == p.X && Y == p.Y);
    }

    //Equalsがtrueを返すときに同じ値を返す
    public override int GetHashCode()
    {
        return (X << 16) ^ Y;
    }

    public Point Clone()
    {
        return new Point(X, Y);
    }

    public void Reverse()
    {
        X = -X;
        Y = -Y;
    }

    public static Point operator +(Point a, Point b)
    {
        return new Point(a.X + b.X, a.Y + b.Y);
    }

    public static Point operator -(Point a, Point b)
    {
        return new Point(a.X - b.X, a.Y - b.Y);
    }

    public static Point operator *(Point a, int i)
    {
        return new Point(a.X * i, a.Y * i);
    }

    public static Point operator /(Point a, int i)
    {
        return new Point(a.X / i, a.Y / i);
    }
    public static Point operator +(Point a)
    {
        return new Point(+a.X, +a.Y);
    }

    public static Point operator -(Point a)
    {
        return new Point(-a.X, -a.Y);
    }

    public override string ToString()
    {
        return string.Format("({0},{1})", X, Y);
    }

    IEnumerable<Point> GetNeighbor()
    {
        yield return new Point(X + 1, Y + 0);
        yield return new Point(X + 0, Y + 1);
        yield return new Point(X - 1, Y + 0);
        yield return new Point(X + 0, Y - 1);
    }

    public IEnumerable<Point> GetNeighbor(Point max)
    {
        return GetNeighbor().Where(p => p.InRange(max));
    }

    public bool InRange(Point max)
    {
        return 0 <= X && X < max.X && 0 <= Y && Y < max.Y;
    }
}

public class Solution
{
    static Point Max;
    static string[] Grid;
    static bool[] Visit;
    static Dictionary<Point, int> RouteCount = new Dictionary<Point, int>();

    static int ToIndex(Point p)
    {
        return p.Y * Max.X + p.X;
    }

    static int Count(Point start)
    {
        if (Grid[start.Y][start.X] != '#')
        {
            return 0;
        }
        if (RouteCount.ContainsKey(start))
        {
            return RouteCount[start];
        }

        var queue = new Queue<Point>();
        var list = new List<Point>();
        queue.Enqueue(start);
        list.Add(start);
        Visit[ToIndex(start)] = true;
        int count = 0;

        while (queue.Count > 0)
        {
            var p = queue.Dequeue();
            var color = Grid[p.Y][p.X];

            foreach (var nei in p.GetNeighbor(Max))
            {
                if (Visit[ToIndex(nei)])
                {
                    continue;
                }
                var neiColor = Grid[nei.Y][nei.X];
                if (color == neiColor)
                {
                    continue;
                }

                if (neiColor == '.')
                {
                    count++;
                }
                else
                {
                    list.Add(nei);
                }
                queue.Enqueue(nei);
                Visit[ToIndex(nei)] = true;
            }
        }
        foreach (var p in list)
        {
            RouteCount[p] = count;
        }

        return count;
    }

    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        Max = new Point(vals[1], vals[0]);
        Grid = new string[Max.Y];
        Visit = new bool[Max.X * Max.Y];
        for (int i = 0; i < Max.Y; i++)
        {
            Grid[i] = Console.ReadLine();
        }

        long count = 0;
        for (int y = 0; y < Max.Y; y++)
        {
            for (int x = 0; x < Max.X; x++)
            {
                count += Count(new Point(x, y));
            }
        }

        Console.WriteLine(count);
    }
}


Measured memory_bytes: 24640