S = STDIN.gets.chomp.split('')

arr = []

S.each_cons(3) {|str| arr.push(str.join('').to_i) }
S.each_cons(4) {|str| arr.push(str.join('').to_i) }

mindiff = 10000
minnum = nil
arr.each do |i|
  diff = (753 - i).abs
  if diff < mindiff
    mindiff = diff
    minnum = i
  end
end

puts mindiff
