N = input() three = N.count('3') if N[0] == '1' and three + 1 == len(N) and N != "1": print(three) else: print(-1)