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