
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val s = sc.next
  val l = s.length

  val ans = (for {
    i <- 0 until l
    j <- i + 1 until l
    k <- j + 1 until l
  } yield ("" + s(i) + s(j) + s(k)).toInt)
    .map(i => math.abs(753 - i))
    .min

  println(ans)
}
