#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>;
 
int main() {
  ll s;
  cin >> s;
  int cnt = 0;
  ll S = s;
  while(S > 0){
    S /= 10;
    cnt++;
  }
  const int f = 753;
  int ans = 1000;
  for(int i = 3; i <= cnt; i++){
    int x = s/pow(10,cnt -i);
    ans = min(abs(x-f), ans);
    ll p = pow(10,cnt+2-i);
    s %= p;
  }
  cout << ans << endl;
}
  
    
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string S;
  cin>>S;
  
  int ans=100000;
  
  
  for(int i=0;i<=S.size()-3;i++){
    string res;
    res[0]=S[i];
    res[1]=S[i+1];
    res[2]=S[i+2];
    
    int X=stoi(res);
    
    ans=min(abs(X-753),ans);
  }
  
  cout<<ans<<endl;
}