#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
int h,w,i,j,suf[3005][3005],suf1[3005][3005];
long long int ans;
string s[3005];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>h>>w;
for(i=0;i<h;i++) cin>>s[i];
for(i=0;i<h;i++){
for(j=w-1;j>=0;j--){
if(j!=w-1) suf[i][j]=suf[i][j+1];
if(s[i][j]=='O') suf[i][j]++;
}
}
for(j=0;j<w;j++){
for(i=h-1;i>=0;i--){
if(i!=h-1) suf1[i][j]=suf1[i+1][j];
if(s[i][j]=='I') suf1[i][j]++;
}
}
ans=0;
for(i=0;i<h;i++) {
for(j=0;j<w;j++) {
if(s[i][j]=='J'){
ans+=suf1[i][j]*suf[i][j];
}
}
}
cout<<ans<<endl;
return 0;
}