#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
 
const int MAXH = 503;
const int MAXW = 503;
int H, W;
char G[MAXH][MAXW];
vector<pair<int,int> > pos[26];
int btween[26][2];
 
int main() {
  while(cin >> H >> W && (H|W)) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
    cin >> G[i][j];
      }
    }
 
    for(int i = 0; i < 26; ++i) pos[i].clear();
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
    if(isalpha(G[i][j])) {
      int k = G[i][j]-'A';
      pos[k].push_back(make_pair(j,i));
      sort(pos[k].begin(), pos[k].end());
    }
      }
    }
 
    fill(btween[0], btween[26], 1<<26);
    for(int k = 0; k < 26; ++k) {
      if(pos[k].empty()) continue;
      if(0) {
      } else if(pos[k][0].first == pos[k][1].first) {
    int begin = min(pos[k][0].second, pos[k][1].second);
    int end = max(pos[k][0].second, pos[k][1].second);
    if(end - begin == 1) continue;
    btween[k][0] = 0;
    int j = pos[k][0].first;
    for(int i = begin+1; i < end; ++i) {
      if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
    }
      } else if(pos[k][0].second == pos[k][1].second) {
    int begin = min(pos[k][0].first, pos[k][1].first);
    int end = max(pos[k][0].first, pos[k][1].first);
    if(end - begin == 1) continue;
    btween[k][0] = 0;
    int i = pos[k][0].second;
    for(int j = begin+1; j < end; ++j) {
      if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
    }
      } else if(pos[k][0].second < pos[k][1].second) {
    btween[k][0] = btween[k][1] = 0;
    for(int i = pos[k][0].second+1, j = pos[k][0].first;
        i < pos[k][1].second; ++i) {
      if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
    }
    for(int i = pos[k][1].second, j = pos[k][0].first;
        j < pos[k][1].first; ++j) {
      if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
    }
 
    for(int i = pos[k][0].second, j = pos[k][0].first+1;
        j < pos[k][1].first; ++j) {
      if(isalpha(G[i][j])) btween[k][1] |= ( 1<<(G[i][j]-'A') );
    }
    for(int i = pos[k][0].second, j = pos[k][1].first;
        i < pos[k][1].second; ++i) {
      if(isalpha(G[i][j])) btween[k][1] |= ( 1<<(G[i][j]-'A') );
    }
      } else {
    btween[k][0] = btween[k][1] = 0;
    for(int i = pos[k][0].second-1, j = pos[k][0].first;
        i > pos[k][1].second; --i) {
      if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
    }
    for(int i = pos[k][1].second, j = pos[k][0].first;
        j < pos[k][1].first; ++j) {
      if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
    }
 
    for(int i = pos[k][0].second, j = pos[k][0].first+1;
        j < pos[k][1].first; ++j) {
      if(isalpha(G[i][j])) btween[k][1] |= ( 1<<(G[i][j]-'A') );
    }
    for(int i = pos[k][0].second, j = pos[k][1].first;
        i > pos[k][1].second; --i) {
      if(isalpha(G[i][j])) btween[k][1] |= ( 1<<(G[i][j]-'A') );
    }
      }
    }
 
    int bit = 0;
    while(1) {
      bool flag = false;
      for(int i = 0; i < 26; ++i) {
    if(bit & (1<<i)) continue;
    if((btween[i][0] & ~bit) == 0 || (btween[i][1] & ~bit) == 0) {
      bit |= (1<<i);
      flag = true;
      break;
    }
      }
      if(!flag) break;
    }
    cout << __builtin_popcount(bit)*2 << endl;
  }
  return 0;
}

Measured memory_bytes: 1448