n = int(input()) w = 1 count = 1 lis = [] while w != n: steps = list(str(bin(w)))[2:] num = 0 for j in steps: num += int(j) if w + num > n: w -= num if w in lis: count = -1 break else: w += num if w in lis: count = -1 break lis.append(w) count += 1 print(count)