#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cstdlib>

#define N 501
#define conv(x) (int)(x-'A')
#define ft first
#define sd second

using namespace std;

typedef pair<int,int> Pa;

struct P{
  int x1, x2, y1, y2;
  P() {}
  P(int _x1, int _y1, int _x2, int _y2): x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}
};

int h, w;
char a[N][N];
map<char, P> mpp;
vector<char> v1, v2;

int xdir[4] = {0, 1, 0, -1}, ydir[4] = {-1, 0, 1, 0};
bool dfs(int sx, int sy, int gx, int gy)
{
  int dr;
  char ch = a[sy][sx];
  if(sx == gx){
    dr = (sy > gy)? 0 : 2;
  } else {
    dr = (sx > gx)? 3 : 1;
  }

  while(!(sx == gx && sy == gy)){
    sx += xdir[dr];
    sy += ydir[dr];
    if(sx < 0 || sx >= w || sy < 0 || sy >= h) return false;
    if(isalpha(a[sy][sx]) && ch != a[sy][sx]) return false;
  }

  return true;
}

int solve()
{
  int t = -1, res = 0;

  while(v1.size() != t){
    t = v1.size();
    v2.clear();

    for(int i = 0; i < t; i++){
      int x1 = mpp[v1[i]].x1, y1 = mpp[v1[i]].y1, x2 = mpp[v1[i]].x2, y2 = mpp[v1[i]].y2;
      if((dfs(x1, y1, x1, y2) && dfs(x2, y2, x1, y2))
	 || (dfs(x1, y1, x2, y1) && dfs(x2, y2, x2, y1))){
	res += 2;
	a[y1][x1] = a[y2][x2] = '.';
      } else {
	v2.push_back(v1[i]);
      }
    }
    v1 = v2;
  }
  v1.clear();
  v2.clear();

  return res;
}

bool check(int p1, int q1, int p2, int q2)
{
  return (abs(p1-p2)+abs(q1-q2) != 1);
}

int main()
{
  bool used[26];
  while(cin>>h>>w && (h+w)){
    map<char, vector<Pa> > mp;
    fill(used, used+26, false);

    for(int i = 0; i < h; i++)
      for(int j = 0; j < w; j++){
	cin >> a[i][j];
	if(isalpha(a[i][j])){
	  vector<Pa> vec;
	  if(used[conv(a[i][j])]) vec = mp[a[i][j]];
	  vec.push_back(Pa(i, j));
	  mp[a[i][j]] = vec;
	  used[conv(a[i][j])] = true;
	}
      }

    for(int i = 0; i < 26; i++){
      char ch = (char)('A'+i);
      if(used[i] && check(mp[ch][0].ft, mp[ch][0].sd, mp[ch][1].ft, mp[ch][1].sd)){
	mpp[ch] = P(mp[ch][0].sd, mp[ch][0].ft, mp[ch][1].sd, mp[ch][1].ft);
	v1.push_back(ch);
      }
    }

    cout << solve() << endl;
    mpp.clear();
  }

  return 0;
}