import scala.io.StdIn._

object Main extends App {
  val S = readLine().toArray.map(_.asDigit).map(_.toString)

  val limit = S.length - 3
  val doggy = for (n <- 0 to limit) yield {
    S(n) + S(n + 1) + S(n + 2)
  }

  val diff = for(e <- doggy) yield {
    Math.abs(753 - e.toInt)
  }

  println(diff.min)

}
