#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll h,w;
cin >> h >> w;
vector<string> a(h);
for (int i=0; i<h; i++) {
cin >> a[i];
}
vector<vector<ll>> pref1(h+1, vector<ll>(w+1)), pref2(h+1, vector<ll>(w+1));
for (int i=1; i<=h; i++) {
for (int j=1; j<=w; j++) {
pref1[i][j] = (a[i-1][j-1]=='O')+pref1[i-1][j]+pref1[i][j-1]-pref1[i-1][j-1];
pref2[i][j] = (a[i-1][j-1]=='I')+pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1];
}
}
ll res = 0;
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
if (a[i][j]!='J') continue;
res+=(pref1[i+1][w]-pref1[i][w]-pref1[i+1][j]+pref1[i][j])*(pref2[h][j+1]-pref2[i][j+1]-pref2[h][j]+pref2[i][j]);
}
}
cout << res;
}