s = gets m = [] while /c[^cw]*w[^w]*w/o =~ s m << $&.length s = $' end puts m.empty? ? -1 : m.min