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
def summa(v,q):
    ans = 0
    k = 1
    while v // k > 0:
        ans += v // k
        k *= q
    return ans

n, k = map(int, input().split())

l = 0
r = n+ 1
while r - l > 1:
    mid = (l+r)//2
    if summa(mid, k) < n:
        l = mid
    else:
        r = mid

print(r)