#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);
for (int i = 0; i < a; i++) {
cin >> s[i];
}
for (int i = 0; i < a; i++) {
for (int k = i + 1; k < a; k++) {
for (int j = 0; j < b; j++) {
for (int l = j + 1; l < b; l++) {
if (s[i][j] == 'J' && s[i][l] == 'O' && s[k][j] == 'I') {
ans++;
}
}
}
}
}
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();
}
}