a=gets.chop.chars.map{|c|eval"1000101021"[c.to_i]};p [1,2].map{|n|a.sum*n+n+a.size*(3-n)}.min