S = gets.chomp n = S.size ans = *[*0...n].product([*0...n]).select {|i, j| S[i..j] =~ /c.*w.*w/}.map {|i, j| j - i + 1}.min || -1 puts ans