#include using namespace std; typedef long long ll; #define rep(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define rrep(i,a,b) for(ll i=(ll)(a-1);i>=(ll)(b);i--) #define MOD 998244353 //#define MOD 1e9+7 #define INF 1e16 //#define PI numbers::pi //#define E numbers::e template bool chmax(T& a,T b){if(a bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} int main(){ ll h,a; cin >> h >> a; ll ans=0,n=1; while(h>0){ h/=a; ans+=n; n*=2; } cout << ans << endl; }