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