#include<bits/stdc++.h>
using namespace std;
int main(){
int h, w;
cin >> h >> w;
string s[h];
int p1[h][w]={}, p2[h][w]={};
for(int i = 0; i < h; i++) {
cin >> s[i];
}
for(int i = 0; i < h; i++){
for(int j = w-1; j>=0; j--){
if(j!=w-1) p1[i][j] = p1[i][j+1];
if(s[i][j]=='O') p1[i][j]++;
}
}
for(int j = 0; j < w; j++){
for(int i = h-1; i>=0; i--){
if(i!=h-1) p2[i][j] = p2[i+1][j];
if(s[i][j]=='I') p2[i][j]++;
}
}
// for(int i = 0; i < h; i++) cout << p1[i]<<" ";
// cout << endl;
// for(int i = 0; i < w; i++) cout << p2[i]<<" ";
// cout << endl;
long long ans = 0;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
if(s[i][j]=='J'){
//cout << i << " "<< j << endl;
ans+=p2[i][j]*p1[i][j];
}
}
}
cout << ans;
}