#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;

typedef pair<int,int> pii;

int num;
vector<pii> v[26];
char ba[500][500];
int m,n;

bool solve() {
    for (int i=0; i<26; ++i) {
        if (v[i].size()) {
            pii a = v[i][0], b = v[i][1];
            //printf("%d,%d %d,%d\n",a.first,a.second,b.first,b.second);
            if (a.first == b.first)  {
                bool f = 0;
                for (int x=min(a.second, b.second)+1; x<=max(a.second, b.second)-1; ++x) {
                    if (ba[a.first][x] !='.') {
                        f = 0;
                        break;
                    }
                    f = 1;
                }
                if (f) {
                    ba[a.first][a.second] = '.';
                    ba[b.first][b.second] = '.';
                    v[i].clear();
                    return 1;
                }
            } else if (a.second == b.second) {
                bool f = 0;
                for (int y=min(a.first, b.first)+1; y<=max(a.first, b.first)-1; ++y) {
                    if (ba[y][b.second] !='.') {
                        f = 0;
                        break;
                    }
                    f = 1;
                }

                if (f) {
                    ba[a.first][a.second] = '.';
                    ba[b.first][b.second] = '.';
                    v[i].clear();
                    return 1;
                }
            } else {
                //a.first, b.second
                bool f = 1;
                for (int y=min(a.first, b.first)+1; y<=max(a.first, b.first)-1; ++y) {
                    //cout << "y=" << y << " " << b.second << endl;
                    if (ba[y][b.second] !='.') {
                        f = 0;
                        break;
                    }
                }
                // cout << f <<" ;" << endl;
                if (f && ba[a.first][b.second] == '.') {
                    
                    for (int x=min(a.second, b.second)+1; x<=max(a.second, b.second)-1; ++x) {
                        if (ba[a.first][x] !='.') {
                            f = 0;
                            break;
                        }
                    }
                    if (f) {
                        //cout << "aaaaa" << endl;
                        ba[a.first][a.second] = '.';
                        ba[b.first][b.second] = '.';
                        v[i].clear();
                        return 1;
                    }
                }
                f = 1;
                
                for (int y=min(a.first, b.first)+1; y<=max(a.first, b.first)-1; ++y) {
                    if (ba[y][a.second] !='.') {
                        f = 0;
                        break;
                    }
                }
                if (f && ba[b.first][a.second] == '.') {
              
                    for (int x=min(a.second, b.second)+1; x<=max(a.second, b.second)-1; ++x) {
                        if (ba[b.first][x] !='.') {
                            f = 0;
                            break;
                        }
                    }
                    if (f) {
                        ba[a.first][a.second] = '.';
                        ba[b.first][b.second] = '.';
                        v[i].clear();
                        return 1;
                    }
                }
            }
        }
    }
    return 0;
}

int main() {
    cin >> m >> n;
    set<char> se;
    for (int i=0; i<m; ++i) {
        for (int j=0; j<n; ++j) {
            cin >> ba[i][j];
            if (ba[i][j] != '.') {
                v[ba[i][j]-'A'].push_back(pii(i,j));
                se.insert(ba[i][j]);
            }
        }
    }
    num = se.size();
    
    int ans = 0;
    while(solve()) {
        ans+=2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1116