import java.util.*;
public class ExchangingCoins {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] dp = new int[n+1];
for(int i=0;i<=n;i++) {
dp[i] = i;
}
for(int i=0;i<=n;i++) {
dp[i] = Math.max(dp[i],dp[i/2]+dp[i/3]+dp[i/4]);
}
System.out.println(dp[n]);
}
}
//when I checked with given example I got the correct answer but in test cases im getting run error