#include<bits/stdc++.h>
using namespace std;
int h,w,ans;
char M[2005][2005];
bool is[2005][2005];
int main()
{
cin>>h>>w;
for(int i=1;i<=h;i++) {
for(int j=1;j<=w;j++) {
cin>>M[i][j];
}
}
while(true) {
bool ok=false;
for(int i=1;i<=h;i++) {
bool flagi=false;
for(int j=2;j<=w;j++) {
if(M[i][j]!=M[i][j-1]||(M[i][j-1]==M[i][j]&&M[i][j]==' ')) {
flagi=true;
break;
}
}
if(!flagi) {
ok=true;
for(int j=1;j<=w;j++) {
is[i][j]=true;
}
}
}
for(int j=1;j<=w;j++) {
bool flagj=false;
for(int i=2;i<=h;i++) {
if(M[i][j]!=M[i-1][j]||(M[i-1][j]==M[i][j]&&M[i][j]==' ')) {
flagj=true;
break;
}
}
if(!flagj) {
ok=true;
for(int i=1;i<=h;i++) {
is[i][j]=true;
}
}
}
for(int i=1;i<=h;i++) {
for(int j=1;j<=w;j++) {
if(is[i][j]) {
M[i][j]=' ';
}
}
}
if(!ok)break;
}
for(int i=1;i<=h;i++) {
for(int j=1;j<=w;j++) {
if(M[i][j]!=' ')ans++;
}
}
cout<<ans;
return 0;
}