#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

inline void reset(int cnt[], int& state) {
	REP(i, 3) cnt[i] = 0;
	state = 0;
}

int main() {
	int ans = 0, cnt[3], state;
	char JOI[] = {'J', 'O', 'I'};

	reset(cnt, state);
	while (1) {
		int c = getchar();

		if (c == JOI[state]) {
			cnt[state]++;
		} else {
			if (state == 2) {
				if (cnt[1] <= min(cnt[0], cnt[2]))
					ans = max(ans, cnt[1]);
				reset(cnt, state);
			} else if (c == JOI[state + 1]) {
				state++;
			} else
				reset(cnt, state);

			if (c == JOI[state]) cnt[state]++;
		}

		if (c == '\n') break;
	}
	cout << ans << endl;

	return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
#define ll long long
const int inf = 1000000000;

int main(){
    string s;
    cin >> s;
    int n=s.size()-2;

    int ans = inf;
    rep(i,n){
        int x=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        ans = min(ans,abs(x-753));
    }
    cout << ans << endl;

        return 0;
    }