strs = gets.chomp.scan(/c.*w.*w/) if strs.length == 0 puts "-1" else chars = strs[0].chars max = chars.length - 1 w1,w2 = false,false res = [] count = 1 0.step(max) do |i| next if chars[i] != "c" (i + 1).step(max) do |j| count += 1 if chars[j] == "w" and not w1 w1 = true elsif chars[j] == "w" and w1 w2 = true end if w1 and w2 res << count break end end count = 1 w1,w2 = false , false end end puts res.min