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