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
from bisect import bisect_right, bisect_left
import os
import sys
from io import BytesIO, IOBase
from math import factorial, floor, inf, ceil, gcd
from collections import defaultdict, deque, Counter
from functools import cmp_to_key
from heapq import heappop, heappush, heapify

BUFSIZE = 8192
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input().strip()
    return(s)
def invr():
    return(map(int,input().split()))
def insr2():
    s = input()
    return(s.split(" "))

###functions

##better sqrt with binary search (since f**k float precision for large nums)

def sqrt(num):
    l, r  = 0, 10**18 + 7
    while r-l != 1:
        mid = (l+r)//2
        square = mid*mid
        if square <= num:
            l = mid
        else:
            r = mid
    return l

### Calculate C(n, r) mod p, where p is prime (fast with precalculation)

def build_mod_inverses(n, r, p):
    fact = [1] * (n + 1)
    for i in range(1, n + 1):
        fact[i] = i * fact[i - 1] % p
    
    inv = [1] * (n + 1)
    inv[n] = pow(fact[n], p - 2, p)
    for i in range(n - 1, -1, -1):
        inv[i] = (i + 1) * inv[i + 1] % p
    
    return fact, inv

# fast C(n, r) mod p calculation using predefined fact and inv
def comb(n, r, p, fact, inv):
    return fact[n] * inv[r] % p * inv[n - r] % p if n >= r >= 0 else 0
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i and i != 1:
                divisors.append(n // i)
    return divisors

def dfs(graph, vertex):
    visited = set()
    tree = []
    deq = deque([vertex])
    while deq:
        vertex = deq.pop()
        if vertex not in visited:
            visited.add(vertex)
            deq.extend(graph[vertex])
            tree.append(vertex)
    return tree

def find_in_sorted_list(elem, sorted_list):
    # https://docs.python.org/3/library/bisect.html
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(sorted_list, elem)
    if i != len(sorted_list) and sorted_list[i] == elem:
        return i
    return -1

############ SEGMENT TREE ##############
class SegmentTree:
    def __init__(self, data, default=0, func=lambda a, b: a+b):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()
 
        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])
 
    def __delitem__(self, idx):
        self[idx] = self._default
 
    def __getitem__(self, idx):
        return self.data[idx + self._size]
 
    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1
 
    def __len__(self):
        return self._len
 
    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        start += self._size
        stop += self._size
 
        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res
 
    def __repr__(self):
        return "SegmentTree({0})".format(self.data)
    
############ DSU ##############
class DisjointSetUnion():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.group = n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
    
        if x == y:
            return
        self.group -= 1
        if self.parents[x] > self.parents[y]:
            x, y = y, x
    
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return self.group
    
    def all_group_members(self):
        dic = {r:[] for r in self.roots()}
        for i in range(self.n):
            dic[self.find(i)].append(i)
        return dic
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

###code

n, k = inlt()

l, r = 0,10**9+1

while r-l != 0:
    mid = (r+l)//2
    
    z = k
    cur = mid
    while True:
        if mid//z == 0:
            break
        cur += mid//z
        z *= k
    if cur > n:
        r = mid
    elif cur < n:
        l = mid+1
    elif cur == n:
        print(mid)
        sys.exit()
        
print(r)