N = input() if N == 1 or N == 3: print -1 else: ret = 0 while N > 1: N -= 3 if N % 10 != 0: print -1 break N /= 10 ret += 1 if N == 1 and ret > 0: print ret