using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int[] HW = IntLine();
        string[] s = new string[HW[0]];
        for (int i = 0; i < HW[0]; i++) s[i] = Console.ReadLine();

        int[] dx = new int[4] { -1, 0, 1, 0 };
        int[] dy = new int[4] { 0, -1, 0, 1 };
        long ans = 0;
        UnionFind uf = new UnionFind(HW[0] * HW[1]);
        for (int i = 0; i < HW[0]; i++)
        {
            for (int j = 0; j < HW[1]; j++)
            {
                for (int d = 0; d < 4; d++)
                {
                    int x = i + dx[d];
                    int y = j + dy[d];
                    if (x < 0 || HW[0] <= x || y < 0 || HW[1] <= y) continue;
                    if (s[i][j] != s[x][y]) uf.Unite(i * HW[1] + j, x * HW[1] + y);
                }
            }
        }

        long[] bc = new long[160000];
        long[] dc = new long[160000];
        for (int i = 0; i < HW[0]; i++)
        {
            for (int j = 0; j < HW[1]; j++)
            {
                if (s[i][j] == '.') dc[uf.Root(i * HW[1] + j)]++;
                else bc[uf.Root(i * HW[1] + j)]++;
            }
        }
        for (int i = 0; i < HW[0] * HW[1]; i++)
        {
            ans += bc[i] * dc[i];
        }
        Console.WriteLine(ans);
    }
}

public class UnionFind
{
    public List<int> parent = new List<int>();

    public UnionFind(int N)
    {
        for (int i = 0; i < N; i++) parent.Add(i);
    }

    public int Root(int a)
    {
        if (parent[a] == a) return a;
        else return parent[a] = Root(parent[a]);
    }

    public void Unite(int a, int b)
    {
        a = Root(a);
        b = Root(b);
        if (a == b) return;
        parent[a] = parent[b];
    }

    public bool Same(int a, int b) { return (Root(a) == Root(b)); }
}
public class AtCoder
{
    public static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int GCD(int a, int b)
    {
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (b != 0)
        {
            d = a % b;
            a = b;
            b = d;
        }
        return a;
    }
    public static long LCM(int a, int b)
    {
        return (long)a * b / GCD(a, b);
    }
    public static string StrReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int IntRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static long[] LSRead()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static long Combination(int n, int r)
    {
        if (n == r || r == 0) return 1;
        return
            Enumerable.Range((n - r + 1), r).ToList().Aggregate((now, next) => now * next) /
            Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next);
    }
    public static long Permutation(int n, int r)
    {
        if (n == r) return 1;
        return
            Enumerable.Range((n - r), r).ToList().Aggregate((now, next) => now * next);
    }
    public static long RepPow(long x, long p, long m = 1000000007)
    {
        if (p == 1) return x % m;
        long b = RepPow(x, p / 2, m) % m;
        if (p % 2 == 0) { return (b * b) % m; }
        else { return (x * ((b * b) % m)) % m; }
    }
    public static long LongRead()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] LongLine()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static int[] IntLine()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
}


Measured memory_bytes: 17248