let s = read_line () in
let n = String.length s in
let d i = int_of_char s.[i] - int_of_char '0' in
let rec loop i prev mi =
    if i = n then mi else
        let cur = (prev * 10 + d i) mod 1000 in
        loop (i + 1) cur (min mi (abs (cur - 753)))
in
loop 2 (d 0 * 10 + d 1) 999 |> Printf.printf "%d\n"