import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; // https://yukicoder.me/problems/no/791 public class Ushi791 { public static void main(String[] args) { // 標準入力から読み込む際に、Scan Scanner sc = new Scanner(System.in); // String 1つ分を読み込む String s = sc.next(); List list = new LinkedList(Arrays.asList(s.split(""))); list.remove(0); List threeList = list.stream().filter(a -> a.equals("3")).collect(Collectors.toList()); if (list.size() == threeList.size() && threeList.size() != 0) { System.out.println(threeList.size()); } else { System.out.println(-1); } } }