s = gets.chomp answer = s.scan(/c[^cw]*?w[^w]*?w/).map(&:length).sort.first || -1 puts answer