#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<iostream>
using namespace std;

int xx=753;

int main(){
  long long s,ma=1000;
  cin >> s;
  
  while(s>100){
    ma=min(ma,abs(s%1000-xx));
    s/=10;
  }
  cout << ma;
}