N = int(input()) if N == 0: print(-1) else: max_k = (N.bit_length() - 1) + 2 max_k = max(max_k, 2) found = False for k in range(2, max_k + 1): # Initial window is [0]*(k-1) + [1] window = [0] * (k - 1) + [1] sum_so_far = 1 # Sum of the current window if N == 1: print(k) found = True break while True: next_term = sum_so_far if next_term > N: break if next_term == N: print(k) found = True break # Update window and sum for the next term calculation popped = window.pop(0) sum_so_far -= popped window.append(next_term) sum_so_far += next_term if found: break if not found: print(-1)