#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<n;i+=2)
using namespace std;
int main(){
  long long n;cin>>n;
  long long ans=10000000000000;
  while(n>100){
    if(ans>abs(753-n%1000))ans=abs(n%1000-753);
    n/=10;
  }
  cout<<ans<<endl;
}