S = list(input()) if S[0]=='1': x = S[1:].count("3") if len(S)-1 == x and 0 < x: print(x) else: print(-1) else: print(-1)