#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections


def get_minimum_moves(n):
    visits = collections.deque(0 for x in range(n + 1))
    queue = collections.deque()
    visits[1] = 1
    queue.append(1)
    while len(queue) > 0:
        u = queue.popleft()
        if u == n:
            return visits[u]
        else:
            bitcount = bin(u).count("1")
            for v in (u + bitcount, u - bitcount):
                if 0 < v <= n and visits[v] == 0:
                    queue.append(v)
                    visits[v] = visits[u] + 1
    return -1


def main():
    print(get_minimum_moves(int(input())))


if __name__ == "__main__":
    main()