#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
const int mod = 1e9+7;
const int inf = 1e18;
const int maxx = 1e6 + 5;
const int lg = 26;
typedef tree <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
void solve() {
int a, b, ans = 0;
cin >> a >> b;
vector <string> s(a);
vector <vector <int> > cnt1(a, vector <int>(b, 0)), cnt2(a, vector <int>(b, 0));
for (int i = 0; i < a; i++) {
cin >> s[i];
}
for (int i = 0; i < a; i++) {
int res = 0;
for (int j = b - 1; j >= 0; j--) {
cnt1[i][j] = res;
if (s[i][j] == 'O') {
res++;
}
}
}
for (int j = 0; j < b; j++) {
int res = 0;
for (int i = a - 1; i >= 0; i--) {
cnt2[i][j] = res;
if (s[i][j] == 'I') {
res++;
}
}
}
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
if (s[i][j] == 'J') {
ans += (cnt1[i][j] * cnt2[i][j]);
}
}
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}