# -*- coding: utf-8 -*- n = list(str(int(input()))) ans = 0 if n[0] == "1": for i in range(1,len(n)): if n[i] == "3": ans += 1 else: print("-1") break else: print(ans) else: print("-1")