#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  ll a;
  cin >> a;
  ll ans = 999;
  while(a>99){
    ans = min(ans,abs(753-a%1000));
    a /= 10;
  }
  cout << ans;
} 

#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;
using ll = long long;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

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

  int mn = 754;
  for(int i=0; i<n-2; ++i){
    string str = s.substr(i,3);
    int num = stoi(str);
    int res = abs(num-753);
    mn = min(mn, res);
  }
  cout << mn;
}  
