N = int(input()) checked = [] now = 1 l_flag = True if(N == 1): print(0) l_flag = False while l_flag: if(now in checked): print(-1) break checked.append(now) now_b = format(now, 'b') o_count = now_b.count('1') if((now + o_count) > N): now -= o_count elif((now + o_count) == N): checked.append(now + o_count) print(len(checked)) break else: now += o_count