const MEMORY = [];
let MEMORY_INDEX = 0;
function print() {
   console.log.apply(null, arguments);
}
function readline() {
   return MEMORY[MEMORY_INDEX++];
}

const RL = require('readline').createInterface({
   input : process.stdin,
   output : process.stdout
});

RL.on('line', (line) => {
   MEMORY.push(line);
});

RL.on('close', solve);

function solve() {
   const T = Number.parseInt(readline(), 10);

   for (let I = 0; I < T; ++I) {
      let bin = readline();
      let oneIndexArr = [-1];
      let answer = 0;
      for (let i = 0; i < bin.length; ++i) {
         if (bin[i] === '1') {
            oneIndexArr.push(i);
         }
      }
      for(let i = 1; i < oneIndexArr.length; ++i) {
         let num = 0;
         let zeroCount = oneIndexArr[i] - oneIndexArr[i - 1] - 1;
         for (let j = oneIndexArr[i]; j < bin.length; ++j) {
            num = (num << 1) + (bin[j] === '1' ? 1 : 0);
            if (num > zeroCount + j - oneIndexArr[i] + 1) {
               break;
            }
            answer++;
         }
      }
      print(answer);
   }
}

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let nnn = 0;
        for (let j = 0, z = 0; j < str.length; j++) {
            if (str[j] === '1') {
                for (let k = j; k < j + (2 * 100000) && k < str.length; k++) {
                    let x = str.substring(j, k + 1);
                    if (parseInt(x, 2) > 2 && z < parseInt(x, 2) - x.length) {
                        break;
                    } else {
                        nnn++;
                    }
                }
                z = 0;
            } else {
                z++;
            }
        }
        console.log(nnn);
    }
});

let inputTextName;
let outTextName;
if (process.argv.length === 5) {
   inputTextName = process.argv[3];
   outTextName = process.argv[4];
}
let MEMORY = [];
let MEMORY_INDEX = 0;

if (inputTextName) {
   const fs = require('fs');
   const path = require('path');
   fs.readFile(path.join(__dirname, inputTextName), 'utf8', (err, data) => {
      MEMORY = data.split('\r\n');
      solve();
   });
} else {
   const RL = require('readline').createInterface({
      input : process.stdin,
      output : process.stdout
   });

   RL.on('line', (line) => {
      MEMORY.push(line);
   });

   RL.on('close', solve);
}

function print() {
   console.log.apply(null, arguments);
}
function readline() {
   return MEMORY[MEMORY_INDEX++];
}

function solve() {
   const T = Number.parseInt(readline(), 10);

   for (let I = 0; I < T; ++I) {
      let bin = readline();
      let oneIndexArr = [-1];
      let answer = 0;
      for (let i = 0; i < bin.length; ++i) {
         if (bin[i] === '1') {
            oneIndexArr.push(i);
         }
      }
      for(let i = 1; i < oneIndexArr.length; ++i) {
         let num = 0;
         let zeroCount = oneIndexArr[i] - oneIndexArr[i - 1] - 1;
         for (let j = oneIndexArr[i]; j < bin.length; ++j) {
            num = (num << 1) + (bin[j] === '1' ? 1 : 0);
            if (num > zeroCount + j - oneIndexArr[i] + 1) {
               break;
            }
            answer++;
         }
      }
      print(answer);
   }
}

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 3192; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length && j < base.length; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 1024; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length && j < base.length; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 4200; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length && j < base.length; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 512; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 256; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length + 1; j++) {
            x += str.split(base[j]).length - 1;
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 2048; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length + 1; j++) {
            x += str.split(base[j]).length - 1;
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        nx = 0;
        for (let j = 1; j < str.length + 1; j++) {
            let jstr = j.toString(2);
            jstr = '0'.repeat(j - jstr.length) + jstr;
            nx += str.split(jstr).length - 1;
        }
        console.log(nx);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 512; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length + 1; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 256; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length + 1; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 3600; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length && j < base.length; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 65535; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length + 1; j++) {
            x += str.split(base[j]).length - 1;
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 3720; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length && j < base.length; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 64; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length; j++) {
            x += str.split(base[j]).length - 1;
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 256; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length && j < base.length; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 256; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x + 1;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length + 1; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const base = [];
for(i = 1; i < 2048; i++) {
    let str = i.toString(2);
    base.push('0'.repeat(i - str.length) + str);
}

let count = (str, f) => {
    let j = 0;
    for (let i = 0; i < str.length; i++) {
        let x = str.indexOf(f, i);
        if (x == -1) {
            break;
        } else {
            j++;
            i = x;
        }
    }

    return j;
}

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input[0]);
    for (let i = 0; i < n; i++) {
        const str = input[i + 1];
        let x = 0;

        for (let j = 0; j < str.length && j < base.length; j++) {
            x += count(str, base[j]);
        }

        console.log(x);
    }
});


function main() {
    var b = readline();

    var indexStart = b.indexOf('[');
    if(indexStart < 0) {
        return -1;
    }

    var b2 =  b.substr(indexStart + 1);
    var index2 = b2.indexOf(':');
    if(index2 < 0) {
        return -1;
    }

    var b3 = b2.substr(index2 + 1);
    var indexLast = b3.lastIndexOf(']');
    if(indexLast < 0) {
        return -1;
    }

    var b4 = b3.substring(0,indexLast);
    var index3 = b4.lastIndexOf(':');
    if(index3 < 0) {
        return -1;
    }

    var bfin = b4.substring(0, index3);
    return bfin.split('|').length + 3
}

print(main());

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });

  let tmp=0, lngth=0, str='';

  rl.on('line', (input) => {
    str=input; rl.close(); therest();
    return 0;}

  );

let therest=function() {
   // console.log(str);
    let len=0;
    let a = str.indexOf('['), b=str.lastIndexOf(']');
    if (a==-1||b==-1||a>b) {console.log(-1); return 0;}

   // console.log(a,b);
    str=str.slice(a+1,b);
    len=2;
    a = str.indexOf(':'), b=str.lastIndexOf(':');
    if (a==-1||b==-1||a==b) {console.log(-1); return 0;}
    str=str.slice(a+1,b);
    len=4;

    for (let char of str) {
        if (char=='|') len++;
    }
    console.log(len);
}

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
let t = 0
rl.on('line', (input) => {
    let s = input.split('')
    let c = 0
    let isAcc = 0
    let op = [-1, -1]
    let cl = [-1, -1]
    for (let i = 0; i < s.length; i++) {
        if (s[i] === '[' && op[0] === -1) {
            op[0] = i
            isAcc++
        } else if (op[0] !== -1 && s[i] === ':' && op[1] === -1) {
            op[1] = i
            isAcc++
            break;
        } else {
            c++
        }
    }
    for (let i = s.length - 1; i > op[1]; i--) {
        if (s[i] === ']' && cl[1] === -1 && cl[0] === -1) {
            cl[1] = i
            isAcc++
        } else if (cl[1] !== -1 && s[i] === ':' && cl[0] === -1) {
            cl[0] = i
            isAcc++
            break;
        } else {
            c++
        }
    }
    for (let i = op[1] + 1; i < cl[0]; i++) {
        if (s[i] !== '|') {
            c++
        }
    }
    rl.close()
    if (isAcc !== 4) {
        console.log(-1)
    } else {
        console.log(s.length - c)
    }
});

var s = readline();
if(s.indexOf('[') != -1) {
    s = s.substring(s.indexOf('['), s.length);
	if(s.lastIndexOf(']') != -1) {
        s = s.substring(0, s.lastIndexOf(']')+1);
        s = s.replace(/[^\:\[\]\|]/gim,'').replace(/[^\:\|]/gim,'');
        s = s.substring(s.indexOf(':'), s.length);
        s = s.substring(0, s.lastIndexOf(':')+1);

        if(s.length >= 2 && s[0] == ':' && s[s.length-1] == ':') {
            s = s.replace(/[^\|]/gim,'');
            print(s.length+4);
        } else {
            print(-1);
        }
    } else {
            print(-1);
    }
} else {
    print(-1);
}

var str = readline()

function getStart(start, end){
  var mask = '[:'
	while(mask && start <=end) {
  	if(str[start] == mask[0]) {
    	mask = mask.slice(1)

      if(!mask)
      	break;
    }
    start++;
  }
  return !mask ? start : -1;
}

function getEnd(start, end){
  var mask = ']:'
	while(mask && start >=end) {
  	if(str[start] == mask[0]) {
    	mask = mask.slice(1)

      if(!mask)
      	break;
    }
    start--;
  }

  return !mask ? start : -1;
}

function getMaxLen() {
    if(str.length < 4) {
        return -1
    }

    var start = getStart(0, str.length-3);
    if(start == -1) {
        return -1;
    }

    var end = getEnd(str.length-1, start+1);
    if(end == -1) {
        return -1;
    }

    var l = 0;
    for(var i=start+1;i<end;i++) {
    	if(str[i] == '|') {
      	    l++;
    	}
    }

    return l+4;
}

print(getMaxLen());

function calc(s) {
  if (s.indexOf('[') === -1) {
    return -1;
  } else {
     s = s.slice(s.indexOf('[') + 1);
  }
  // print(s);

  if (s.indexOf(':') === -1) {
    return -1;
  } else {
     s = s.slice(s.indexOf(':') + 1);
  }
  // print(s);

  if (s.lastIndexOf(']') === -1) {
    return -1;
  } else {
     s = s.slice(0, s.lastIndexOf(']'));
  }
  // print(s);

  if (s.lastIndexOf(':') === -1) {
    return -1;
  } else {
     s = s.slice(0, s.lastIndexOf(':'));
  }
  // print(s);

  return 4 + s.filter(elem => elem === '|').length;
}

var s = readline().split("");

print(calc(s));

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });

  let tmp=0, lngth=0, str='';

  rl.on('line', (input) => {
    str=input; rl.close(); therest();
    return 0;}

  );

let therest=function() {
    console.log(str);
    let len=0;
    let a = str.indexOf('['), b=str.lastIndexOf(']');
    if (a==-1||b==-1||a>b) {console.log(-1); return 0;}

   // console.log(a,b);
    str=str.slice(a+1,b);
    len=2;
    a = str.indexOf(':'), b=str.lastIndexOf(':');
    if (a==-1||b==-1||a==b) {console.log(-1); return 0;}
    str=str.slice(a+1,b);
    len=4;

    for (let char of str) {
        if (char=='|') len++;
    }
    console.log(len);
}

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
let t = 0
rl.on('line', (input) => {
    let s = input.split('')
    let c = 0
    let isAcc = 0
    let op = [0, 0]
    let cl = [0, 0]
    for (let i = 0; i < s.length; i++) {
        if (s[i] === '[' && op[0] === 0) {
            op[0] = i
            isAcc++
        } else if (op[0] !== 0 && s[i] === ':' && op[1] === 0) {
            op[1] = i
            isAcc++
            break;
        } else {
            c++
        }
    }
    for (let i = s.length - 1; i > op[1]; i--) {
        if (s[i] === ']' && cl[1] === 0 && cl[0] === 0) {
            cl[1] = i
            isAcc++
        } else if (cl[1] !== 0 && s[i] === ':' && cl[0] === 0) {
            cl[0] = i
            isAcc++
            break;
        } else {
            c++
        }
    }
    for (let i = op[1]+1; i < cl[0]; i++) {
        if (s[i] !== '|') {
            c++
      }
    }
    rl.close()
    if (isAcc !== 4) {
        console.log(-1)
    } else {
        console.log(c)
    }
});

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
let t = 0
rl.on('line', (input) => {
    let s = input.split('')
    let c = 0
    let isAcc = 0
    let op = [0, 0]
    let cl = [0, 0]
    for (let i = 0; i < s.length; i++) {
        if (s[i] === '[' && op[0] === 0) {
            op[0] = i
            isAcc++
        } else if (op[0] !== 0 && s[i] === ':' && op[1] === 0) {
            op[1] = i
            isAcc++
            break;
        } else {
            c++
        }
    }
    for (let i = s.length - 1; i > op[1]; i--) {
        if (s[i] === ']' && cl[1] === 0 && cl[0] === 0) {
            cl[1] = i
            isAcc++
        } else if (cl[1] !== 0 && s[i] === ':' && cl[0] === 0) {
            cl[0] = i
            isAcc++
            break;
        } else {
            c++
        }
    }
    for (let i = op[1]+1; i < cl[0]; i++) {
        if (s[i] !== '|') {
            c++
      }
    }
    rl.close()
    if (isAcc !== 4) {
        console.log(-1)
    } else {
        console.log(s.length-c)
    }
});

var s = readline();
s = s.substring(s.indexOf('['), s.length);
s = s.substring(0, s.lastIndexOf(']')+1);
s = s.replace(/[^\:\[\]\|]/gim,'').replace(/[^\:\|]/gim,'');
s = s.substring(s.indexOf(':'), s.length);
s = s.substring(0, s.lastIndexOf(':')+1);
if((s.match(/\:/g) || []).length != 2) {
    print(-1);
} else {
    print(s.length+2);
}

var s = readline();
s = s.substring(s.indexOf('['), s.length);
s = s.substring(0, s.lastIndexOf(']')+1);
s = s.replace(/[^\:\[\]\|]/gim,'').replace(/[^\:\|]/gim,'');
s = s.substring(s.indexOf(':'), s.length);
s = s.substring(0, s.lastIndexOf(':')+1);

if(s.length >= 2 && s[0] == ':' && s[s.length-1] == ':') {
	s = s.replace(/[^\|]/gim,'');

    print(s.length+4);
} else {
	print(-1);
}

function calc(s) {
  if (s.indexOf('[') === -1) {
    return -1;
  } else {
     s = s.slice(s.indexOf('['));
  }

  if (s.indexOf(':') === -1) {
    return -1;
  } else {
     s = s.slice(s.indexOf(':'));
  }

  if (s.lastIndexOf(']') === -1) {
    return -1;
  } else {
     s = s.slice(0, s.lastIndexOf(']') + 1);
  }

  if (s.lastIndexOf(':') === -1) {
    return -1;
  } else {
     s = s.slice(0, s.lastIndexOf(':') + 1);
  }

  return 4 + s.filter(elem => elem === '|').length;
}

var s = readline().split("");

print(calc(s));


'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const M = 2 * m + n + 10;
  let h = new Array(2 * n).fill(-1),
      te = new Array(M),
      ne = new Array(M),
      w = new Array(M);
  let idx = 0;
  const add = (i, j, c) => {
    te[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;
  };
  for (let i = 0; i < m; i++) {
    let [u, v, w] = await rns();
    u--, v--;
    add(u, v, w);
    add(v + n, u + n, w);
  }
  for (let i = 0; i < n; i++) add(i, i + n, 0);
  const djk = () => {
    const dist = new Array(2 * n).fill(Infinity);
    const queue = new Heap((a, b) => a[1] - b[1]);
    dist[0] = 0;
    queue.push([0, 0]);
    const vis = new Array(2 * n);
    while (queue.size()) {
      const [u, d] = queue.pop();
      if (vis[u]) continue;
      vis[u] = 1;
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = te[i];
        if (vis[v]) continue;
        if (dist[v] > dist[u] + w[i]) {
          dist[v] = dist[u] + w[i];
          queue.push([v, dist[v]]);
        }
      }
    }
    return dist;
  };
  const dist = djk();
  return dist.slice(n + 1).map(num => num === Infinity ? -1 : num).join(' ');
}
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
}

async function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log('zdebug' + error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const M = 2 * m + n + 10;
  let h = new Array(2 * n).fill(-1),
      te = new Array(M),
      ne = new Array(M),
      w = new Array(M);
  let idx = 0;
  const add = (i, j, c) => {
    te[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;
  };
  for (let i = 0; i < m; i++) {
    let [u, v, w] = await rns();
    u--, v--;
    add(u, v, w);
    add(v + n, u + n, w);
  }
  for (let i = 0; i < n; i++) add(i, i + n, 0);
  const djk = () => {
    const dist = new Array(2 * n).fill(Infinity);
    const queue = new Heap((a, b) => a[1] - b[1]);
    dist[0] = 0;
    queue.push([0, 0]);
    const vis = new Array(2 * n);
    while (queue.size()) {
      const [u, d] = queue.pop();
      if (vis[u]) continue;
      vis[u] = 1;
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = te[i];
        if (vis[v]) continue;
        if (dist[v] > dist[u] + w[i]) {
          dist[v] = dist[u] + w[i];
          queue.push([v, dist[v]]);
        }
      }
    }
    return dist;
  };
  const dist = djk();
  return dist.slice(n + 1).map(num => num === Infinity ? -1 : num).join(' ');
}
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
}

async function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log('zdebug' + error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
void async function () {
  let idx = 0;
  const read = () => inputs[idx++];
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  let h = new Array(n).fill(-1),
      hs = new Array(n).fill(-1),
      e = [],
      ne = [],
      w = [];
  const add = (h, i, j, c) => {
    e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1;
  };
  const time = new Date().valueOf();
  for (let i = 0; i < m; i++) {
    const [u, v, w] = await rns();
    add(h, u - 1, v - 1, w);
    add(hs, v - 1, u - 1, w);
  }
  if (n === 100000) console.log(new Date().valueOf() - time);
  const djk = (dist, queue, h) => {
    const vis = new Array(n);
    while (queue.size()) {
      const [u, d] = queue.pop();
      if (vis[u]) continue;
      vis[u] = 1;
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        if (dist[v] > dist[u] + w[i]) {
          dist[v] = dist[u] + w[i];
          queue.push([v, dist[v]]);
        }
      }
    }
  };
  const dist = new Array(n).fill(Infinity);
  {
    const queue = new Heap((a, b) => a[1] - b[1]);
    dist[0] = 0;
    queue.push([0, 0]);
    djk(dist, queue, h);
  }
  if (n !== 100000) {
    const queue = new Heap((a, b) => a[1] - b[1], dist.map((d, i) => [i, d]));
    djk(dist, queue, hs);
  }
  return dist.slice(1).map(num => num === Infinity ? -1 : num).join(' ');
}
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    _defineProperty(this, "_map", new Map());
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    this._map.set(this._heap[i], j);
    this._map.set(this._heap[j], i);
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._map.set(node, this._heap.length);
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this._map.set(val, i);
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
  getIndex(val) {
    return this._map.get(val);
  }
}

async function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log('zdebug' + error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  let h = new Array(n).fill(-1),
      hs = new Array(n).fill(-1),
      e = [],
      ne = [],
      w = [];
  const add = (h, i, j, c) => {
    e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1;
  };
  const time = new Date().valueOf();
  for (let i = 0; i < m; i++) {
    const [u, v, w] = await rns();
    add(h, u - 1, v - 1, w);
    add(hs, v - 1, u - 1, w);
  }
  if (n === 100000) console.log(new Date().valueOf() - time);
  const djk = (dist, queue, h) => {
    const vis = new Array(n);
    while (queue.size()) {
      const [u, d] = queue.pop();
      if (vis[u]) continue;
      vis[u] = 1;
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        if (dist[v] > dist[u] + w[i]) {
          dist[v] = dist[u] + w[i];
          queue.push([v, dist[v]]);
        }
      }
    }
  };
  const dist = new Array(n).fill(Infinity);
  {
    const queue = new Heap((a, b) => a[1] - b[1]);
    dist[0] = 0;
    queue.push([0, 0]);
    djk(dist, queue, h);
  }
  if (n !== 100000) {
    const queue = new Heap((a, b) => a[1] - b[1], dist.map((d, i) => [i, d]));
    djk(dist, queue, hs);
  }
  return dist.slice(1).map(num => num === Infinity ? -1 : num).join(' ');
}
const n = 100000,
      m = 200000;
const edges = [`${n} ${m}`];
for (let i = 0; i < m; i++) {
  let x = Math.floor(Math.random() * n),
      y = Math.floor(Math.random() * n);
  while (x === y) {
    y = Math.floor(Math.random() * n);
  }
  edges.push(`${x} ${y} ${Math.floor(Math.random() * 100000)}`);
}
let i = 0;
const read$1 = () => edges[i++];
void async function () {
  console.time('test');
  await solve(read$1);
  console.timeEnd('test');
}();
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    _defineProperty(this, "_map", new Map());
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    this._map.set(this._heap[i], j);
    this._map.set(this._heap[j], i);
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._map.set(node, this._heap.length);
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this._map.set(val, i);
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
  getIndex(val) {
    return this._map.get(val);
  }
}

async function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log('zdebug' + error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ')
    .map(Number);
  };
  const [n, m] = await rns();
  const M = 2 * m + 10;
  let h = new Array(n).fill(-1),
      hs = new Array(n).fill(-1),
      e = new Array(M),
      ne = new Array(M),
      w = new Array(M);
  let idx = 0;
  const add = (h, i, j, c) => {
    e[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;
  };
  for (let i = 0; i < m; i++) {
    const [u, v, w] = await rns();
    add(h, u - 1, v - 1, w);
    add(hs, v - 1, u - 1, w);
  }
  const djk = (dist, queue, h, nodes = new Array(n)) => {
    const vis = new Array(n);
    while (queue.size()) {
      const [u, d] = queue.pop();
      if (vis[u]) continue;
      vis[u] = 1;
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        if (dist[v] > dist[u] + w[i]) {
          dist[v] = dist[u] + w[i];
          if (!nodes[v]) {
            nodes[v] = [v, dist[v]];
            queue.push(nodes[v]);
          } else {
            const j = queue.getIndex(nodes[v]);
            nodes[v][1] = dist[v];
            queue.modify(j, nodes[v]);
          }
        }
      }
    }
  };
  const dist = new Array(n).fill(Infinity);
  {
    const queue = new Heap((a, b) => a[1] - b[1]);
    dist[0] = 0;
    queue.push([0, 0]);
    djk(dist, queue, h);
  }
  {
    const nodes = dist.map((d, i) => [i, d]);
    const queue = new Heap((a, b) => a[1] - b[1], nodes);
    djk(dist, queue, hs, nodes);
  }
  return dist.slice(1).map(num => num === Infinity ? -1 : num).join(' ');
}
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    _defineProperty(this, "_map", new Map());
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) {
        this.down(i);
        this._map.set(arr[i], i);
      }
    }
  }
  swap(i, j) {
    this._map.set(this._heap[i], j);
    this._map.set(this._heap[j], i);
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._map.set(node, this._heap.length);
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this._map.set(val, i);
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
  getIndex(val) {
    return this._map.get(val);
  }
}

async function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log('zdebug' + error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ')
    .map(Number);
  };
  const [n, m] = await rns();
  const M = 2 * m + 10;
  let h = new Array(n).fill(-1),
      hs = new Array(n).fill(-1),
      e = new Array(M),
      ne = new Array(M),
      w = new Array(M);
  let idx = 0;
  const add = (h, i, j, c) => {
    e[idx] = j, w[idx] = c, ne[idx] = h[i], h[i] = idx++;
  };
  for (let i = 0; i < m; i++) {
    const [u, v, w] = await rns();
    add(h, u - 1, v - 1, w);
    add(hs, v - 1, u - 1, w);
  }
  const djk = (dist, queue, h, nodes = new Array(n)) => {
    const vis = new Array(n);
    while (queue.size()) {
      const [u, d] = queue.pop();
      if (vis[u]) continue;
      vis[u] = 1;
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        if (dist[v] > dist[u] + w[i]) {
          dist[v] = dist[u] + w[i];
          if (!nodes[v]) {
            nodes[v] = [v, dist[v]];
            queue.push(nodes[v]);
          } else {
            const j = queue.getIndex(nodes[v]);
            nodes[v][1] = dist[v];
            queue.modify(j, nodes[v]);
          }
        }
      }
    }
  };
  const dist = new Array(n).fill(Infinity);
  {
    const queue = new Heap((a, b) => a[1] - b[1]);
    dist[0] = 0;
    queue.push([0, 0]);
    djk(dist, queue, h);
  }
  {
    const nodes = dist.map((d, i) => [i, d]);
    const queue = new Heap((a, b) => a[1] - b[1], nodes);
    djk(dist, queue, hs, nodes);
  }
  return dist.slice(1).map(num => num === Infinity ? -1 : num).join(' ');
}
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    _defineProperty(this, "_map", new Map());
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    this._map.set(this._heap[i], j);
    this._map.set(this._heap[j], i);
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._map.set(node, this._heap.length);
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this._map.set(val, i);
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
  getIndex(val) {
    return this._map.get(val);
  }
}

async function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log('zdebug' + error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();


function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var len = +readline(); // длина
    var s = readline(); // строка
    s = removeLastEvens(s, len);
    findResult(s, s.length);
  }
}

function removeLastEvens(str, len) {
  while (str && Number(str.slice(-1)) % 2 === 0) {
    str = str.substring(0, len - 1);
    len -= 1;
  }
  return str;
}

function findResult(str, len) {
  if (!str) {
    print(-1);
    return;
  }
  var sum = 0;
  for (var j = 0; j < len; j++) {
    sum += Number(str[j]);
  }
  if (sum % 2 === 0) {
    print(str);
  } else {
    str = removeOdd(str, str.length);
    if (!str || Number(str[str.length - 1]) % 2 === 0) {
      print(-1);
    } else {
      str = str.replace(/^(0+)/, "");
      print(str);
    }
  }
}

function removeOdd(str, len) {
  for (var k = 0; k < len; k++) {
    if (str[k] % 2 === 1) {
      str = str.substring(0, k) + str.substring(k + 1);
      return str;
    }
  }
  return 0;
};

main();

function check(digits) {
  var num = "";
  var sum = 0;

  for (var i = digits.length - 1; i >= 0; i--) {
    var d = parseInt(digits[i]);
    if (num.length < 1 && d % 2 < 1) continue;

    num = d.toString() + num;
    sum += d;
    if (sum % 2 < 1) return num;
  }
  return -1;
}

var t = parseInt(readline());
var l = 0;
while (t > 0) {
  if (l == 0) {
    readline();
    l = 1;
  } else {
    l = 0;
    t--;
    print(check(readline()));
  }
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let ans = '';

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (c % 2 === 1) {
    c++;
    return;
  }

  const odd = [];
  for (let i = 0; i < d.length; i++) {
    if (d[i] % 2) {
      odd.push(d[i]);
    }

    if (odd.length === 2) {
      break;
    }
  }

  if (odd.length === 2) {
    ans += odd.join('') + '\n';
  }
  else {
    ans += '-1\n';
  }

  c++;
});

rl.on('close', () => {
  console.log(ans);
});

'use strict';

const { createInterface } = require('readline');

const rl = createInterface({
  input: process.stdin,
  crlfDelay: Infinity
})
const lines = [];
let nextLine = 0;
rl.on('line', (line) => {
  lines.push(line);
});

rl.on('close', () => {
  main();
});

function readline() {
  return lines[nextLine++];
}

function solve (nStr) {
  const nArr = nStr.split('').map(Number);
  while ((nArr.length > 1) && (nArr[nArr.length-1] % 2 === 0)) {
    nArr.pop();
  }
  if (nArr.length < 2) {
    return '-1';
  }
  const sum = nArr.reduce((a, b) => a + b, 0);
  if (sum % 2 === 1) {
    for(let i = nArr.length - 2; i >= 0; i--) {
      if (nArr[i] % 2 === 1) {
        nArr.splice(i, 1);
        return nArr.join('');
      }
    }
    return '-1';
  } else {
    return nArr.join('');
  }
}

function main() {
  const t = parseInt(readline());
  for(let i = 0; i < t; i++) {
    readline();
    const line = readline();
    const res = solve(line);
    console.log(res);
  }
}

function getSum(num, digits) {
  var sum = 0;

  for (var i = 0; i < digits; ++i) {
    sum += Number(num[i]);
  }

  return sum;
}

function isEvenNumber(sum) {
  return sum % 2 === 0;
}

function isOddNumber(sum) {
  return sum % 2 !== 0;
}

function isOdd(num, digits) {
  return isOddNumber(num[digits - 1]);
}

function isStrange(num, digits, sum) {
  return isOdd(num, digits) && isEvenNumber(sum);
}

function processItem() {
  var digits = +readline();
  var num = readline();
  var tempNum = num;
  var tempSum = getSum(num, digits);
  var tempDigits = digits;

  while (!isOdd(tempNum, tempDigits, tempSum) && tempDigits > 1) {
    tempSum = tempSum - tempNum[tempDigits - 1];
    tempNum = tempNum.slice(0, tempDigits - 1);
    tempDigits--;
  }

  var currentIndex = tempDigits - 2;

  while (isOddNumber(tempSum) && tempDigits > 1 && currentIndex >= 0) {
    var n = Number(tempNum[currentIndex]);

    if (isOddNumber(n) || n === 0) {
      tempSum = tempSum - tempNum[currentIndex];
      tempNum = tempNum.slice(0, currentIndex) + tempNum.slice(currentIndex + 1);
      tempDigits--;
    }

    currentIndex--;
  }

  print(isStrange(tempNum, tempDigits, tempSum) ? tempNum : '-1');
}

function processItems() {
  var itemsCount = +readline();
  var items = [];

  for (var i = 0; i < itemsCount; ++i) {
    processItem();
  }

  return items;
}

processItems();

var numRun= readline();

for(var n=0;n<numRun;n++){
    var k=readline();
    var s=prepNum(readline());
    var sum=0;
    var cur="";
    var found=false;
    out:for(var i=0;i<s.length;i++){
        sum=parseInt(s[i]);
        cur=s[i];
        //check(cur,sum);
        if(check(cur,sum)){break out;}
       // if(check(cur,sum)){print("TRUE:"+cur);};
        for(var k=i+1;k<s.length;k++){
            sum+=parseInt(s[k]);
            cur+=s[k];
            //check(cur,sum);
           if(check(cur,sum)){break out;}
            //if(check(cur,sum)){print("TRUE:"+cur);};
        }
    }//out
    if(found){print(cur);}
    else{print(-1);}
}//num runs

//want overall number (str) to be odd and sum of digits (sum) to be even
function check(str,sum){
   // print(str);
   // print("CHECK:"+str+":"+sum);
    if(parseInt(str)%2===1&&sum%2===0){found=true;return true;}
    return false;
}

//can remove even numbers as they don't do anything and 0's
function prepNum(str){
    var newStr="";
    for(var i=0;i<str.length;i++){
        if(parseInt(str[i])%2!==0){newStr+=str[i];}
    }
    return newStr;
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
    var t = myconv(next(),1);
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var N = myconv(next(),1);
        var s = next();
        if(N == 1){
            output[i] = "-1";
            continue;
        }
        var list = myconv(s,7);
        var sum = 0;
        var odds = new Set();
        var evens = new Set();
        var outputS = "";
        for(var j = 0; j < N; j++){
            sum += list[j];
            outputS += list[j].toString();
            if(list[j] % 2 != 0 && sum % 2 == 0){
                output[i] = outputS;
                break;
            }
        }
        if(output[i] == null){
            output[i] = "-1";
        }
    }
    myout(myconv(output,9));
}

var numRun= readline();

for(var n=0;n<numRun;n++){
    var k=readline();
    var s=delZer(readline());
    var sum=0;
    var cur="";
    var found=false;
    out:for(var i=0;i<s.length;i++){
        sum=parseInt(s[i]);
        cur=s[i];
        check(cur,sum);
        //if(check(cur,sum)){break out;}
       // if(check(cur,sum)){print("TRUE:"+cur);};
        for(var k=i+1;k<s.length;k++){
            sum+=parseInt(s[k]);
            cur+=s[k];
            check(cur,sum);
           // if(check(cur,sum)){break out;}
            //if(check(cur,sum)){print("TRUE:"+cur);};
        }
    }//out
    if(found){print(cur);}
    else{print(-1);}
}//num runs

//want overall number (str) to be odd and sum of digits (sum) to be even
function check(str,sum){
    print(str);
   // print("CHECK:"+str+":"+sum);
    if(parseInt(str)%2===1&&sum%2===0){found=true;return true;}
    return false;
}

function delZer(str){
    var newStr="";
    for(var i=0;i<str.length;i++){
        if(str[i]!=="0"){newStr+=str[i];}
    }
    return newStr;
}

var numRun= readline();

for(var n=0;n<numRun;n++){
    var k=readline();
    var s=delZer(readline());
    var sum=0;
    var cur="";
    var found=false;
    out:for(var i=0;i<s.length;i++){
        sum=parseInt(s[i]);
        cur+=s[i];
        if(check(cur,sum)){break out;}
       // if(check(cur,sum)){print("TRUE:"+cur);};
        for(var j=i+1;j<s.length;j++){
            for(var k=j;k<s.length;k++){
                sum+=parseInt(s[k]);
                cur+=s[k];
                if(check(cur,sum)){break out;}
                //if(check(cur,sum)){print("TRUE:"+cur);};
            }
        }
    }//out
    if(found){print(cur);}
    else{print(-1);}
}//num runs

//want overall number (str) to be odd and sum of digits (sum) to be even
function check(str,sum){
   // print("CHECK:"+str+":"+sum);
    if(parseInt(str)%2===1&&sum%2===0){found=true;return true;}
    return false;
}

function delZer(str){
    var newStr="";
    for(var i=0;i<str.length;i++){
        if(str[i]!=="0"){newStr+=str[i];}
    }
    return newStr;
}

var numRun= readline();

for(var n=0;n<numRun;n++){
    var k=readline();
    var s=readline();
    var sum=0;
    var cur="";
    var found=false;
    out:for(var i=0;i<s.length;i++){
        sum=parseInt(s[i]);
        cur+=s[i];
        if(check(cur,sum)){break out;}
       // if(check(cur,sum)){print("TRUE:"+cur);};
        for(var j=i+1;j<s.length;j++){
            for(var k=j;k<s.length;k++){
                sum+=parseInt(s[k]);
                cur+=s[k];
                if(check(cur,sum)){break out;}
                //if(check(cur,sum)){print("TRUE:"+cur);};
            }
        }
    }//out
    if(found){print(cur);}
    else{print(-1);}
}//num runs

//want overall number (str) to be odd and sum of digits (sum) to be even
function check(str,sum){
   // print("CHECK:"+str+":"+sum);
    if(parseInt(str)%2===1&&sum%2===0){found=true;return true;}
    return false;
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
    var t = myconv(next(),1);
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var N = myconv(next(),1);
        var s = next();
        if(N == 1){
            output[i] = "-1";
            continue;
        }
        var list = myconv(s,7);
        var sum = 0;
        var odds = new Set();
        var evens = new Set();
        for(var j = 0; j < N; j++){
            sum += list[j];
            if(list[j] % 2 == 0){
                evens.add(list[j]);
            }else{
                if(i < N - 1){
                    odds.add(j);
                }
            }
        }
        if(sum % 2 == 0){
            while(s.length > 0){
                var migihasi = myconv(s.slice(-1));
                if(migihasi % 2 != 1){
                    s = s.slice(0,s.length - 1);
                }else{
                    break;
                }
            }
            if(s != ""){
                output[i] = s;
            }else{
                output[i] = "-1";
            }
        }else{
            odds = Array.from(odds);

            list.splice(odds[0],odds[0] + 1);
            while(list.length > 0){
                if(list[0] == 0){
                    list.splice(0,1);
                }else{
                    break;
                }
            }
            if(list.length == 0){
                output[i] = "-1";
            }else{
                output[i] = myconv(list,0);
            }
        }
    }
    myout(myconv(output,9));
}