#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	string S; cin>>S;
	int ans=100000;
	for(int i=0;i<S.size()-2;i++){
		int X=stoi(S.substr(i,3));
		ans=min(ans,abs(X-753));
	}
	cout<<ans<<endl;
}