object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val S = sc.next()
  val steps = (0 until S.length - 2).map(i => Array(S(i), S(i + 1), S(i + 2)))
  println(steps.map(i => math.abs(753 - new String(i).toInt)).min)
}
