#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int inf=1e9;
typedef long long ll;
int M,N;
string board[505];

int hit(int hity,int hitx)
{
    int ret=0;
    char up='-',down='-',right='-',left='-';
    int leftx,rightx,upy,downy;
    for(int y=hity;y>=0;y--)
    {
        if(board[y][hitx]!='.')
        {
            up=board[y][hitx];
            upy=y;
            break;
        }
    }
    for(int y=hity;y<M;y++)
    {
        if(board[y][hitx]!='.')
        {
            down=board[y][hitx];
            downy=y;
            break;
        }
    }
    for(int x=hitx;x>=0;x--)
    {
        if(board[hity][x]!='.')
        {
            left=board[hity][x];
            leftx=x;
            break;
        }
    }
    for(int x=hitx;x<N;x++)
    {
        if(board[hity][x]!='.')
        {
            right=board[hity][x];
            rightx=x;
            break;
        }
    }
    if(right!='-')
    {
        if(right==left) board[hity][rightx]='.',board[hity][leftx]='.',right='-',left='-',ret+=2;
        else if(right==up) board[hity][rightx]='.',board[upy][hitx]='.',right='-',up='-',ret+=2;
        else if(right==down) board[hity][rightx]='.',board[downy][hitx]='.',right='-',down='-',ret+=2;
    }
    if(left!='-')
    {
        if(left==right) board[hity][leftx]='.',board[hity][rightx]='.',left='-',right='-',ret+=2;
        else if(left==up) board[hity][leftx]='.',board[upy][hitx]='.',left='-',up='-',ret+=2;
        else if(left==down) board[hity][leftx]='.',board[downy][hitx]='.',left='-',down='-',ret+=2;
    }
    if(up!='-')
    {
        if(up==right) board[upy][hitx]='.',board[hity][rightx]='.',up='-',right='-',ret+=2;
        else if(up==left) board[upy][hitx]='.',board[hity][leftx]='.',up='-',left='-',ret+=2;
        else if(up==down) board[upy][hitx]='.',board[downy][hitx]='.',up='-',down='-',ret+=2;
    }
    if(down!='-')
    {
        if(down==right) board[downy][hitx]='.',board[hity][rightx]='.',up='-',right='-',ret+=2;
        else if(down==left) board[downy][hitx]='.',board[hity][leftx]='.',up='-',left='-',ret+=2;
        else if(down==up) board[upy][hitx]='.',board[downy][hitx]='.',up='-',down='-',ret+=2;
    }
    return ret;
}

int check()
{
    int change=0;
    for(int i=0;i<M;i++)
    {
        for(int j=0;j<N;j++)
        {
            if(board[i][j]=='.') 
            {
                change+=hit(i,j);
            }
        }
    }
    return change;
}   

int main()
{
	while(cin >> M >> N && M)
    {
        int ans=0;
        for(int i=0;i<M;i++)
        {
            cin >> board[i];
        }
        while(1)
        {
            int inc=check();
            ans+=inc;
            if(inc==0)break;
        }
        cout << ans << endl;
    }
	
}

