/**
 * Created by IntelliJ IDEA.
 * User: m09kaa3
 * Date: Sep 30, 2009
 * Time: 8:23:03 PM
 * To change this template use File | Settings | File Templates.
 */
import java.io.*;
import java.util.*;
public class Trucs {
    public static void main(String[] args) throws Exception{
        Scanner s=new Scanner (new File("trucks.in"));
        PrintWriter p = new PrintWriter(new File("trucks.out"));
                int n=s.nextInt();
        int k=s.nextInt();
        int deg1=1;
        int deg2=1;
        for(int i=1;i<=n*2;i*=2){
          if (i>n){deg1=i/2;}
        }
        for(int i=1;i<=k*2;i*=2){
          if (i>k){deg2=i/2;}
        }
       long sum= deg1/deg2 +(n-deg1)/k;
        p.print(sum);
        p.close();
    }
}
