import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String N = sc.next(); sc.close(); if(N.charAt(0) != '1' || N.length() == 1) { System.out.println(-1); System.exit(0); } for(int i = 1; i < N.length(); i++) { char c = N.charAt(i); if(c != '3') { System.out.println(-1); System.exit(0); } } System.out.println(N.length() - 1); } }