#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
typedef std::stack<long long> llStack;
typedef std::stack<char> charStack;

using namespace std;
using ll = long long;
typedef pair <int, int> pii;
int main()
{
    ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
    ll n;
    ll memo[1003][1003] = {};
    ll memo2[1003][1003] = {};
    char tmp;
    //ll y[1003][1003] = {};
    //ll y[100005] = {};
    //ll z[100005] = {};
    string s[1003];
    llStack xStack;
    llStack yStack;

    llStack memoxStack;
    llStack memoyStack;

    charStack Stack;
    cin >> a;
    cin >> b;
    for (int i = 0; i < a; i++)
    {
        cin >> s[i];
    }
    for (int i = 0; i < a; i++)
    {
        for (int k = 0; k < b; k++)
        {
            if (s[i][k] == '#'&&memo2[i][k]==0)
            {
                memo2[i][k]=1;
                //for (int z = 0; z < a; z++)
                {
                    //for (int y = 0; y < b; y++)
                    {
                        //memo[z][y] = 0;
                    }
                }
              h=0;
              f=1;
                yStack.push(i);
                xStack.push(k);
                memoyStack.push(i);
                memoxStack.push(k);
              
                Stack.push('#');
                while (xStack.size() > 0)
                {
                    c = yStack.top();
                    yStack.pop();
                    d = xStack.top();
                    xStack.pop();
                    tmp = Stack.top();
                    Stack.pop();
                    memo[c][d] = 1;
                    //cout << c << endl;
                    //cout << d << endl;
                    if (0 <= c+1&&c+1 < a && 0 <= d&&d < b&&memo[c+1][d] == 0 && s[c+1][d] != tmp)
                    {
                      h=1;
                      if ((i + k) % 2 != (c + 1+d) %2)
                        {
                            e++;
                        }
                        else
                        {
                            f++;
                        }
                        yStack.push(c+1);
                        xStack.push(d);
                      memoyStack.push(c+1);
                memoxStack.push(d);
                        memo[c + 1][d] = 1;
                        memo2[c+1][d] = 1;
                        if (tmp == '#')
                        {
                            Stack.push('.');
                        }
                        else
                        {
                            Stack.push('#');
                        }
                        //cout << yStack.top() << endl;
                        //cout << xStack.top() << endl;
                        //cout << Stack.top() << endl;

                    }
                    if (0 <= c-1&&c-1 < a && 0 <= d&&d < b&&memo[c-1][d] == 0 && s[c-1][d] != tmp)
                    {
                      h=1;
                      if ((i + k) % 2 != (c -1+d) %2)
                        {
                            e++;
                        }
                        else
                        {
                            f++;
                        }
                        yStack.push(c-1);
                        xStack.push(d);
                      memoyStack.push(c-1);
                memoxStack.push(d);
                        memo[c - 1][d] = 1;
                        memo2[c-1][d] = 1;
                        if (tmp == '#')
                        {
                            Stack.push('.');
                        }
                        else
                        {
                            Stack.push('#');
                        }

                    }
                    if (0 <= c&&c < a && 0 <= d+1&&d+1 < b&&memo[c][d+1] == 0 && s[c][d+1] != tmp)
                    {
                      h=1;
                      if ((i + k) % 2 != (c + 1+d) %2)
                        {
                            e++;
                        }
                        else
                        {
                            f++;
                        }
                        yStack.push(c);
                        xStack.push(d+1);
                      memoyStack.push(c);
                memoxStack.push(d+1);
                        memo[c][d + 1] = 1;
                        memo2[c][d+1] = 1;
                        if (tmp == '#')
                        {
                            Stack.push('.');
                        }
                        else
                        {
                            Stack.push('#');
                        }

                    }
                    if (0 <= c&&c < a && 0 <= d-1&&d-1 < b&&memo[c][d-1] == 0 && s[c][d-1] != tmp)
                    {
                      h=1;
                      if ((i + k) % 2 != (c - 1+d) %2)
                        {
                            e++;
                        }
                        else
                        {
                            f++;
                        }
                        yStack.push(c);
                        xStack.push(d-1);
                      memoyStack.push(c);
                memoxStack.push(d-1);
                        memo[c][d - 1] = 1;
                        memo2[c][d-1] = 1;
                        if (tmp == '#')
                        {
                            Stack.push('.');
                        }
                        else
                        {
                            Stack.push('#');
                        }
                        
                    }
                    
                    //cout << endl;

                }
                
              if(h==1){
                /*for (int z = 0; z < a; z++)
                {
                    for (int y = 0; y < b; y++)
                    {
                        if ((i + k) % 2 != (z + y) % 2 && memo[z][y] == 1)
                        {
                            e++;
                        }
                        else if(memo[z][y] == 1)
                        {
                            f++;
                        }
                    }
                }
                */
                ans += e*f;
                e = 0;
                f = 0;
                //cout << e << endl;
                //cout << f << endl;
                //cout << endl;
                //memset(memo, 0, sizeof(memo));
                while (memoxStack.size() > 0)
                {
                  memo[memoyStack.top()][memoxStack.top()]=0;
                  memoyStack.pop();
                  memoxStack.pop();
                }
                //for (int z = 0; z < a; z++)
                {
                    //for (int y = 0; y < b; y++)
                    {
                        //memo[z][y] = 0;
                    }
                }
              }
              memo[c][d]=0;
            }
        }
    }

    cout << ans << endl;
    //cout << ans << endl;

    ////std::cout << std::fixed;
    //cout << std::setprecision(20) << << endl;
    //cout << d+1 << endl;
    //cout << "" << endl;

    return 0;
}

Measured memory_bytes: 20224