#include<bits/stdc++.h>
#define fi first
#define se second
#define int long long
#define pii pair<int,int>
#define el '\n'
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define N 1000006
using namespace std;
char A[3003][3003];
int col[3003][3003], row[3003][3003];
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> A[i][j];
row[i][j] = row[i][j - 1] + (A[i][j] == 'O');
col[i][j] = col[i - 1][j] + (A[i][j] == 'I');
}
}
int ans = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (A[i][j] == 'J' && row[i][m] - row[i][j] > 0 && col[n][j] - col[i][j] > 0) {
ans += (row[i][m] - row[i][j]) * (col[n][j] - col[i][j]);
}
}
}
cout << ans;
}