#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    string s;
    int ans=INF;
    cin >> s;
    
    rep(i,s.size()-2){
        int now = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0')*1;
        ans = min(ans,abs(753-now)); 
    }
    
    cout << ans;
    
    return 0;
}
#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  ll s;
  cin >> s;
  ll ans = s;
  while(s >= 100)
  {
    ans = min(ans, abs((s % 1000) - 753));
    s /= 10;
  }
  cout << ans;
  
}

int main()
{
  fastio;
  solve();

  return 0;
}