n = input() if n[0] != '1': print(-1) else: cnt = 0 for i in range(1,len(n)): if n[i] != '3': print(-1) exit() else: cnt += 1 print(cnt)