function syukusyou(yx){
   var cnt=0;
   yx=yx.filter(v=>{
      var flag = v.every(val=> val==".");
      if(!flag){
         cnt=0;
         return true;
      }else if(flag && cnt==0){
         cnt++;
         return true;
      }else {
         return false;
      }
   });
   return yx;
}

function kaiten(yx){
   return  yx[0].map((a, i) => yx.map(b => b[i]));
}

function saikiY(y,x,d){
   if(yx[y][x] != ".")return yx[y][x];
   else if(y+d!=-1 && y+d!=h)return saikiY(y+d,x,d);
   else return ".";
}

function saikiX(y,x,d){
   if(yx[y][x]!=".")return yx[y][x];
   else if(x+d!=-1 && x+d!=w)return saikiX(y,x+d,d);
   else return ".";
}

function kesu(y,x){
   var arr= [saikiY(y,x,1),saikiY(y,x,-1),saikiX(y,x,1),saikiX(y,x,-1)];
   var a = arr.filter(function (x, i, self) {
      if(x==".")return false;
      return self.indexOf(x) === i && i !== self.lastIndexOf(x);
   });
   a.forEach(v=> replaceFn(y,x,v));
   return a.length*2;
}

function replaceFn(y,x,s){
   for(var i=0;i<h;i++){
      if(yx[i][x]==s)yx[i][x]=".";
   }
   for(var i=0;i<w;i++){
      if(yx[y][i]==s)yx[y][i]=".";
   }
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var yx = arr.slice(1).map(v=> v.split(""));
yx=syukusyou(yx);
yx=kaiten(yx);
yx=syukusyou(yx);
var h=yx.length;
var w=yx[0].length;
var sum=0;
while(true){
   var flag=false;
   yx.forEach((ary,y)=>{
      ary.forEach((v,x)=>{
         if(v=="."){
            var add = kesu(y,x);
            if(add != 0)flag=true;
            sum += add;
         }
      });
   });
   if(!flag)break;
}
console.log(sum);
