#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using P = pair<int, int>;

int main() {
    int m, n;
    cin >> m >> n;
    vector<string> tile(m);
    vector<vector<P>> v(26);
    for(int i=0; i<m; ++i) {
        cin >> tile[i];
        for(int j=0; j<n; ++j) {
            if(tile[i][j] != '.') {
                v[tile[i][j]-'A'].push_back(P{j, i});
            }
        }
    }
    int ans = 0;
    while(true) {
        v.erase(remove_if(v.begin(), v.end(), [](auto const& vv) {
            return vv.empty();
        }), v.end());
        bool update = false;
        for(auto& x : v) {
            P p1 = x[0], p2 = x[1];
            if(p1.first == p2.first) {
                bool ok = (min(p1.second, p2.second)+1 != max(p1.second, p2.second));
                for(int i=min(p1.second, p2.second)+1; i<max(p1.second, p2.second); ++i) {
                    if(tile[i][p1.first] != '.') {
                        ok = false;
                        break;
                    }
                }
                if(ok) {
                    tile[p1.second][p1.first] = tile[p2.second][p2.first] = '.';
                    x.clear();
                    update = true;
                    ans += 2;
                }
            } else if(p1.second == p2.second) {
                bool ok = (min(p1.first, p2.first) + 1 != max(p1.first, p2.first));
                for(int i=min(p1.first, p2.first)+1; i<max(p1.first, p2.first); ++i) {
                    if(tile[p1.second][i] != '.') {
                        ok = false;
                        break;
                    }
                }
                if(ok) {
                    tile[p1.second][p1.first] = tile[p2.second][p2.first] = '.';
                    x.clear();
                    update = true;
                    ans += 2;
                }
            } else {
                int x1 = p1.first, y1 = p2.second;
                int x2 = p2.first, y2 = p1.second;
                bool ok = true;
                for(int i=(x1 < x2 ? x1 : x2+1); i<=(x1 < x2 ? x2-1 : x1); ++i) {
                    if(tile[y1][i] != '.') {
                        ok = false;
                        break;
                    }
                }
                for(int i=(y1 < y2 ? y1 : y2+1); i<=(y1 < y2 ? y2-1 : y1); ++i) {
                    if(tile[i][x1] != '.') {
                        ok = false;
                        break;
                    }
                }
                if(ok) {
                    tile[p1.second][p1.first] = tile[p2.second][p2.first] = '.';
                    ans += 2;
                    update = true;
                    x.clear();
                    continue;
                }

                ok = true;
                for(int i=(x2 < x1 ? x2 : x1+1); i<=(x2 < x1 ? x1-1 : x2); ++i) {
                    if(tile[y2][i] != '.') {
                        ok = false;
                        break;
                    }
                }
                for(int i=(y2 < y1 ? y2 : y1+1); i<=(y2 < y1 ? y1-1 : y2); ++i) {
                    if(tile[i][x2] != '.') {
                        ok = false;
                        break;
                    }
                }
                if(ok) {
                    tile[p1.second][p1.first] = tile[p2.second][p2.first] = '.';
                    ans += 2;
                    update = true;
                    x.clear();
                    continue;
                }
            }
        }
        if(!update) {
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3276