N = input() List = [] for i in range(101): List.append("1" + i * "3") if N in List: print(List.index(N)) elif N == 1: print("-1") else: print("-1")