#include<bits/stdc++.h>
using namespace std;
#define ll long long
int h,w;
string s[3005];
unordered_map<int,int> rows;
unordered_map<int,int> colum;
unordered_map<int,map<int,int>> rowsfin;
unordered_map<int,map<int,int>> columfin;
int main(){
cin >> h >> w;
for(int i=0;i<h;i++) cin >> s[i];
for(int i=0;i<h;i++){
int x=0;
for(int j=0;j<w;j++){
if(s[i][j]=='O') x++;
rowsfin[i][j+1]=x;
}
rows[i]=x;
}
for(int i=0;i<w;i++){
int x=0;
for(int j=0;j<h;j++){
if(s[j][i]=='I') x++;
columfin[i][j+1]=x;
}
colum[i]=x;
}
ll ans=0;
for(ll i=0;i<h;i++){
for(ll j=0;j<w;j++){
ll a,b,c,d;
a=rows[i];
b=rowsfin[i][j];
c=colum[j];
d=columfin[j][i];
if(s[i][j]=='J') ans+=((a-b)*(c-d));
}
}
cout << ans << endl;
}