let input = require('fs').readFileSync('/dev/stdin', 'utf8'); let ans = [input.match(/c[^c]*?w.*?w/g), input.match(/c[^c]*?w[*c]*?w/g), [...input].reverse().join('').match(/w.*?w[^w]*?c/g), input.match(/c.?w.?w/g)]; ans = ans.filter(v => v).map(v => Math.min(...v.map(v => v.length))); console.log(ans.length ? Math.min(...ans) : -1);