import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {
    val s = StdIn.readLine().toList.map(_.asDigit)
    println(solve(s))
  }

  def solve(s: List[Int]): Int = {
    def solveRec(s: List[Int], acc: Int): Int = {
      s match {
        case x :: (t @ y :: z :: _) =>
          val cand = (x * 100 + y * 10 + z - 753).abs
          solveRec(t, acc min cand)
        case _ => acc
      }
    }
    solveRec(s, 1000)
  }

}
