n = gets.chomp o = n.reverse.chop.reverse s = o.size t = o.chars.count('3') p (n[0] != '1' or s != t or t == 0) ? -1 : s