cx = { '0' => 1, '1' => 0, '2' => 0, '3' => 0, '4' => 1, '5' => 0, '6' => 1, '7' => 0, '8' => 2, '9' => 1 } s = gets.chomp n = s.size m = s.chars.map { |c| cx[c] }.inject(:+) + 1 p [2 * m + n, 2 * n + m].min