#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
using namespace std;

const int num = 653;

int main() {
  string s, c;
  cin >> s;
  
  int l = s.size(), ans = 0, minAns = num, p;
  
  for(int i = 0; i < l - 2; ++i)
  {
    c = s.substr(i, 3);
    stringstream str(c);
    str >> ans;
    p = abs(ans - 753);
    if(p < minAns)
      minAns = p;
  }
  cout << minAns;
  return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s; cin >> s;

  int ans = INF;
  rep(i,s.size()-2){
    string t = "";
    t+=s[i];
    t+=s[i+1];
    t+=s[i+2];
    int tmp = stoi(t);
    ans = min(ans,abs(753-tmp));
  }

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