using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (h, a) = (c[0], c[1]);
        var ans = 0L;
        var cnt = 1L;
        while (h > 0)
        {
            ans += cnt;
            h /= a;
            cnt <<= 1;
        }
        WriteLine(ans);
    }
}