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)]; ans = ans.filter(v => v); console.log(ans.length ? Math.min(...ans.map(v => v[0].length)) : -1);