const input = require('fs').readFileSync('/dev/stdin', 'utf8'); console.log( [...input .slice(1, --input.length)] .every(v => v == 3) && input.length > 2 && input[0] == 1? input.length - 2 : -1 );