import java.io.*; import java.util.Scanner; public class Main_yukicoder791 { private static Scanner sc; private static Printer pr; private static void solve() { char[] n = sc.next().toCharArray(); if (n[0] != '1' && n.length == 1) { pr.println(-1); return; } for (int i = 1, size = n.length; i < size; i++) { if (n[i] != '3') { pr.println(-1); return; } } pr.println(n.length - 1); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }