// Your code here!
import std.stdio, std.math, std.conv;

void main(){
  //string S = "1234567876";
  //string S = "35753";
  //string S = "1111111111";
  string S;
  readf("%s", &S);

  int T = 753;

  string X;
  int min = T;
  for (int i = 0; i < S.length - 2; i++) {
    //writeln("i : ", i);
    X = S[(i)..(i+3)];
    //writeln("X : ", X);
    int tmp = abs(T - X.to!int);
    if (min > tmp) {
      min = tmp;
      //writeln("check_min : ", min);
    }
  }
  //writeln("min : ", min);
  writeln(min);
}