#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;



int main() {
  string S; cin >>S;
  ll ans = INF;
  rep(i,S.size()-2){
    ll ints = stoi(S.substr(i,3)); 
    ans = min(ans,abs(753 - ints));
  }

  cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int intinput() {
	int x;
	cin >> x;
	return x;
}
vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	vector<int> s(10);
	string ss;
	cin >> ss;
	for(int i = 0;i < ss.length();i++){
		s[i] = ss.at(i) - '0';
	}
	int cnt =100000;
	for(int i = 0;i < ss.length()-2;i++){
		if(100*s[i] + 10*s[i+1] + s[i+2] -753 <= 0){
			if((100*s[i] + 10*s[i+1] + s[i+2] - 753)*-1 < cnt){
				cnt = (100*s[i] + 10*s[i+1] + s[i+2] - 753)*-1;
			}
		}else{
			if(100*s[i] + 10*s[i+1] + s[i+2] - 753 < cnt){
				cnt = 100*s[i] + 10*s[i+1] + s[i+2] - 753;
			}
		}
	}
	cout << cnt << endl;
}