import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val s = sc.next

    val ans = new Array[Int](s.length - 2)

    for (i <- 0 to s.length - 3) {
      val m = s(i).toString + s(i + 1).toString + s(i + 2).toString
      ans(i) = math.abs(m.toInt - 753)
    }

    println(ans.min)
  }
}
