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