import java.util.Scanner;

public class Zadatak1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		long V = scan.nextLong();

		int q = 1;
		long qw = 0;
		while (V != 0) {
			long t = 1;
			long i = 1;
			int m = 0;
			long z = 0;
			while (i <= V) {
				t = V / i;
				z = i;
				if (m % 3 == 0) {
					i = i * 2;
				} else if (m % 3 == 1) {
					i = (long) (i * 2.5);
				} else {
					i = i * 2;
				}
				m = m + 1;
			}
			qw = qw + t;
			V = V - t * z;
		}

		System.out.println(qw);
	}
}