import scala.io.StdIn.readLine

object Main extends App {
  val s = readLine()
  val len = s.length
  
  val result = (0 to len - 3).map { i =>
    val x = s.take(i + 3).takeRight(3).toInt
    (x - 753).abs
  }.min
  println(result)
}