One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/837a798d4a0c3fe486d62834783caae40b612564.png" style="max-width: 100.0%;max-height: 100.0%;"/> lines, drinks another cup of tea, then he writes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6304306dbf5ca2b95ecc97210a073c7ce7046290.png" style="max-width: 100.0%;max-height: 100.0%;"/> lines and so on: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2cdc02455a9281e93e689009c03121270d92d1bc.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92bb2b6b977058290f73ae4b98682b9f08f27633.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/858a837a4b30b8578ae73e5bde2c4e213fa93c32.png" style="max-width: 100.0%;max-height: 100.0%;"/>, ...

The expression <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b5e5ef3e6404b5c0e793de54b932298d1825cced.png" style="max-width: 100.0%;max-height: 100.0%;"/> is regarded as the integral part from dividing number *a* by number *b*.

The moment the current value <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c126a89a41a4df209f523e85223b11f89735ebba.png" style="max-width: 100.0%;max-height: 100.0%;"/> equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.

Vasya is wondering, what minimum allowable value *v* can take to let him write not less than *n* lines of code before he falls asleep.
The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1 ≤ *n* ≤ 10<sup class="upper-index">9</sup>, 2 ≤ *k* ≤ 10.
7 2
4
59 9
54
1 9
1
11 2
7
747 2
376
6578 2
3293
37212 2
18609
12357 2
6181
7998332 2
3999172
86275251 2
43137632
75584551 2
37792280
6 3
5
43 4
33
811 3
543
3410 4
2560
21341 4
16009
696485 4
522368
8856748 3
5904504
2959379 4
2219538
831410263 3
554273516
2 5
2
19 6
17
715 7
615
9122 5
7300
89117 6
74268
689973 7
591408
3024524 5
2419624
67127156 6
55939302
412262167 7
353367574
6 8
6
59 9
54
246 10
222
5314 8
4651
15309 9
13609
35648 10
32085
3018012 8
2640764
92153348 9
81914089
177583558 10
159825206
1000000000 2
500000008
1000000000 3
666666672
1000000000 4
750000005
1000000000 5
800000003
1000000000 6
833333338
1000000000 7
857142861
1000000000 8
875000004
1000000000 9
888888894
1000000000 10
900000001
1 4
1
2 10
2
1 2
1
6 8
6
987862820 9
878100288
979591791 9
870748262
948889213 9
843457081
8 9
8
999999999 10
900000000
import sys,math
from bisect import bisect_left , bisect_right 


def rd(): return sys.stdin.readline().strip()
def rdl(typ,sep=" "): return list(map(typ, rd().split(sep)))
def wt(x,sep="\n") : sys.stdout.write(str(x) + sep)    # string / num
def wtBoolUp(x): wt("YES" if x else "NO")  # True = YES/ False =NO
def wtBoolLow(x): wt("Yes" if x else "No")  # True = Yes/ False =No
def wtlArr(arr,sep=" "):   # Print arr in single line
    for x in arr: wt(x, " ") 
    wt("")
def wtlsArr(arr):  # Print arr in mult lines
    for x in arr: wt(x)
def wtlsArrArr(arr):    # print Arrays in multiple lines
    for a in arr: wtlArr(a)


# for dfs use this and use 'yield' during dfs and at last
from types import GeneratorType
def bootstrap(f, stack=[]):              
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to
    return wrappedfunc

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

INF = 10**18
mod = 10**9 + 7    

def binPow(a,b,mod) :
    res = 1
    while b :
        if b % 2: 
            res = res * a % mod
        a = a * a % mod
        b //= 2
    return res

def invMod(x,mod): return pow(x,mod-2,mod)      

def getFacts(n,mod):   # O(n)
    fact = [1]*(n+1)
    for i in range(2,n+1): fact[i] = (i*fact[i-1])%mod
    return fact

def nCr(n, r, fact, mod) :  # O(logMOD)
    num = fact[n]       # numerator
    den = (fact[r] * fact[n - r]) % mod   # denominator
    return (num * invMod(den, mod)) % mod

def lcm(num1,num2):
    hcf = math.gcd(num1,num2)
    lcm_ = (num1*num2)//hcf
    return lcm_

def sqrtFloat(num):  # req : https://codeforces.com/contest/1809/problem/B
    l, r = 0 , num
    res = 0
    while l <= r :
        mid = (l+r)//2
        if mid*mid <= num :
            res = mid
            l = mid + 1
        else : #number will be on l side
            r = mid-1
    
    return res + 0.1*(res*res != num)

def floorDiv(a,b): return a//b
def ceilDiv(a,b): return (a+b-1)//b

def prefixSum(arr):   # 0 at last of prefix sum
    pref = [0]*(len(arr)+1)
    for i in range(len(arr)): pref[i] = arr[i] + pref[i-1]
    return pref

def prefixXor(arr):   # 0 at last of prefix Xor
    pref = [0]*(len(arr)+1)
    for i in range(len(arr)): pref[i] = arr[i] ^ pref[i-1]
    return pref

def apNth(n, a=1, d=1) : return a+(n-1)*d
def apSum(n, a=1, d=1):  return (2*a+(n-1)*d)*n//2
def apSumMod(n, a=1, d=1, mod=mod):  return ((2*a+(n-1)*d)*n*invMod(2,mod))%mod
def apSumRange(l, r, d=1) : return apSum((r-l+1)//d, l, d)
def apSumRangeMod(l, r, d=1, mod=mod) : return apSumMod((r-l+1)//d, l, d, mod)

def hypot(p1,p2):
    return ((p2[0]-p1[0])**2 + (p2[1]-p1[1])**2)**0.5
def manhat(p1,p2):
    return abs(p2[0]-p1[0]) + abs(p2[1]-p1[1])

def comb(n,r):   # for small x otherwise TC higher
    res = 1
    for i in range(r) : res = res*(n-i)//(i+1)   # res*(n-i) % (i+1) == 0  always
    return res

def powerArr(base,n,mod):
    pwr = [1]*(n+1)
    for i in range(1,n+1):
        pwr[i] = (base*pwr[i-1]) % mod
    return pwr

def getClosest(num,sortArr,notTake=-INF,notTakeCnt=1):
    idx = bisect_left(sortArr,num)  # find closest to x , not take notTake
    closeArr = []
    for i in range(max(0,idx-2),min(len(sortArr),idx+3)) : # [idx-2,idx-1,idx,idx+1,idx+2]
        if notTakeCnt>0 and sortArr[i] == notTake:
            notTakeCnt -= 1
            continue
        closeArr.append(sortArr[i])
    return min(closeArr, key=lambda x:abs(x-num),default=-INF)

def grouping(itr, notTake=INF):  # grouping of similar elements
    n = len(itr)
    res = []
    i = 0
    while i < n:
        st = i
        while i+1 <n and itr[i] == itr[i+1] :
            i += 1
        if itr[st] != notTake:
            res.append([itr[st],st,i,i-st+1])
        i += 1
    return res

def dirnsRD() : return [(0,1),(1,0)]
def dirnsLU() : return [(0,-1),(-1,0)]
def dirns(): return [(0,1),(1,0),(0,-1),(-1,0)]  # RDLU
def dirnsDiag(): return dirns() + [(1,1),(1,-1),(-1,1),(-1,-1)]
def chessDirns(): return [(-2,-1),(-1,-2),(1,-2),(2,-1),(2,1),(1,2),(-1,2),(-2,1)]

def cntBits(x): 
    cnt = 0
    while x > 0:
        x &= x - 1   # remove last set bit
        cnt +=1
    return cnt
def isRepSumP2(num, x): return cntBits(num) <= x <= num  # num in sum two's power in x moves ?
def binry(decimal): return bin(decimal).replace('0b', '')
def deciml(binary): return int(str(binary),2)
def printAllBin(arr):
    maxLen = len(binry(max(arr)))
    for x in arr:
        curr = binry(x)
        res = " ".join(list("0"*(maxLen-len(curr))+curr))
        wt( res + f"   <- {x}")

def c2i(ch,up=0): return ord(ch) - ord('A' if up else 'a')  # ch to integer
def i2c(n,up=0): return chr(ord('A' if up else 'a') + n)    # integer to ch

def setPrecRound(num, cnt): return round(num, cnt)
def setPrec(num, cnt): return format(num,f".{cnt}f")
def flush(): sys.stdout.flush()
def clearCache(func): func.cache_clear()   # used to clear the lru cache for every new test case



# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
''' ॐॐ _/\_ हर हर महादेव _/\_ ॐॐ '''

# sys.setrecursionlimit(300_005)
# mod = 10**9 + 7


def isValid(v, k, n):
    p = math.floor(math.log(v,k) + 1)  # max power at which 0 = number of terms
    kp = k**(p-1)
    num = v*(kp*k - 1)
    den = kp*(k-1)
    sm = num // den
    return sm >= n


def solve():
    n,k = rdl(int)
    ##  -----------------------------------------  
    
    l,r = 0,n   # (l,r]
    while l + 1 < r:
        mid = (l+r)//2
        if isValid(mid,k,n):
            r = mid
        else:
            l = mid    
    return r


# Don't forget the mod and recursion limit and INF

wt(solve())
