#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
using namespace std;
char str[1000000];
int main() {
  int ans, k, len, J, O, I;
  int a;
  //string str;
  
  while(scanf("%s", str) != EOF) {
    len = strlen(str);
    J=0, O=0, I=0;
    ans=0, k=0;
    //cout << len << endl;
    for(int i = 0 ; i < len ; i++) {
      if(str[i] != 'J') continue;

      if(str[i] == 'J') {
	if(str[i] != '#') a = i;
	while(str[a] == 'J') {
	  str[a] = '#';
	  a++;
	  J++;
	}
	if(str[a] == 'O') {
	  while(str[a] == 'O') {
	    a++;
	    O++;
	  }
	  if(str[a] == 'I') {
	    while(str[a] == 'I') {
	      a++;
	      I++;
	    }
	  }
	}
      }
      //printf("J = %d, O = %d, I = %d\n", J, O, I);
      if(O <= J && O <= I) k = min(J, min(O, I));
      //if(J == O && O == I /*|| J <= O && O >= I*/) k = min(J, min(O, I));
      //else J = 0; O = 0; I = 0;
      ans = max(k, ans);
      J = 0; O = 0; I = 0;
        
    }
    cout << ans << endl;
  }
  return 0;
}
#include<bits/stdc++.h>
using namespace std;

int main() {

  string s;
  int flag = -1, ans = 0;
  int J = 0, O = 0, I = 0;
  cin >> s;

  for(int i=0; i<s.size(); i++) {
    if( flag <= 0 && s[i] == 'J' ) {
      flag = 0;
      J++;
    }
    else if( flag == 0 && s[i] == 'O' ) {
      flag = 1; O++;
    }
    else if( flag == 1 && s[i] == 'O' ) {
      O++;
    }
    else if( flag == 1 && s[i] == 'I' ) {
      flag = 2; 
      if( J >= O ) {
	I++;
	ans = max(1, ans);
      } 
      else {
	flag = -1;
	J = O = I = 0;
      }
    }
    else if( flag == 2 && s[i] == 'I' ) {
      I++; 
      if( I >= O ) {
	ans = max(ans, min(J, min(O, I)));
      }
    }
    else {
      if( s[i] == 'J' ) {
	flag = 0;
	J = 1; O = I = 0;
      }
      else {
	flag = -1;
	J = O = I = 0;
      }
    }
  }

  cout << ans << endl;
}