#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
int h,w,count = 0;
cin >> h >> w;
string temp;
vector<string> mp;
vector<vector<int> > ingots(h,vector<int> (w,0)), ores(h,vector<int> (w,0));
vector<vector<int> > ingotsum(h,vector<int> (w,0)),oresum(h,vector<int> (w,0));
for(int i = 0; i < h; i++){
cin >> temp;
mp.push_back(temp);
}
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
if(mp[i][j] == 'I'){
ingots[i][j] = 1;
}
if(mp[i][j] == 'O'){
ores[i][j] = 1;
}
}
}
for(int i = h-1; i >= 0; i--){
for(int j = w-1; j >= 0; j--){
if(i == h-1){
ingotsum[i][j] = ingots[i][j];
}else{
ingotsum[i][j] = ingotsum[i+1][j] + ingots[i][j];
}
if(j == w-1){
oresum[i][j] = ores[i][j];
}else{
oresum[i][j] = oresum[i][j+1] + ores[i][j];
}
}
}
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
if(mp[i][j] == 'J'){
count = count + (oresum[i][j]*ingotsum[i][j]);
}
}
}
cout << count;
}