import java.util.Scanner

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

  def taskA() = {
    val ans = sc.nextInt() match {
      case 7 | 5 | 3 => "YES"
      case _ => "NO"
    }
    println(ans)
  }

  def taskB() = {
    val s = sc.next()
    val n = s.length
    val ans = 0.until(n - 2).fold(10000) { (acc, x) =>
      val y = s.substring(x, x + 3).toInt
      Math.min(acc, Math.abs(y - 753))
    }
    println(ans)
  }

  taskB()
}
