N = input() li = [] for i in range(1,102): li.append("1"+"3"*i) li = [-1] + li print(li.index(N))