5 3
 1000 3
 777 17
 4 3
 2 2
 100 4
 10 4
 999 2
 6 4
 1 2
 17 3
 1 4
 26 8
 91 5
 1 3
 1000 2
 20 3
 9 4
 123 5
 1000 1000
 3 2
 3 3
 80 970
 1000 4
 1 1000

7
 1499
 825
 5
 3
 133
 13
 1997
 7
 1
 25
 1
 29
 113
 1
 1999
 29
 11
 153
 1001
 5
 4
 80
 1333
 1

'''
def main():
    from sys import stdin,stdout
if __name__=='__main__':
    main()
'''
#1A
'''
def main():
    from sys import stdin,stdout
    from math import ceil
    n,m,a=map(int,stdin.readline().split())
    stdout.write(str(ceil(n/a)*ceil(m/a)))
if __name__=='__main__':
    main()
'''
#4A
'''
def main():
    from sys import stdin,stdout
    i=int(stdin.readline())
    if i&1:
        stdout.write('NO\n')
    else:
        if i//2 >1:
            stdout.write('YES\n')
        else:
            stdout.write('NO\n')
if __name__=='__main__':
    main()
'''
#71A
'''
def main():
    from sys import stdin,stdout
    for _ in range(int(stdin.readline())):
        s=stdin.readline().strip()
        if len(s) <=10:
            stdout.write(s+'\n')
        else:
            stdout.write(s[0]+str(len(s[1:-1]))+s[-1]+'\n')
if __name__=='__main__':
    main()
'''
#158A
'''
def main():
    from sys import stdin,stdout
    n,k=map(int,stdin.readline().split())
    a=list(map(int,stdin.readline().split()))
    count=0
    for i in range(n):
        if a[i] and a[i]>=a[k-1]:
            count+=1
    stdout.write(str(count))
if __name__=='__main__':
    main()
'''
#188A
'''
def main():
    from sys import stdin,stdout
    s=stdin.readline().strip()
    t=''
    s=s.lower()
    for i in s:
        if i not in 'aeiouy':
            t+='.'+i
    stdout.write(t)
if __name__=='__main__':
    main()
'''
#50A
'''
def main():
    from sys import stdin,stdout
    n,m=map(int,stdin.readline().split())
    stdout.write(str((n*m)//2))
if __name__=='__main__':
    main()
'''
#231A
'''
def main():
    from sys import stdin,stdout
    count=0
    for _ in range(int(stdin.readline())):
        if sum(list(map(int,stdin.readline().split())))>=2:
            count+=1
    stdout.write(str(count))
if __name__=='__main__':
    main()
'''
#282A
'''
def main():
    from sys import stdin,stdout
    x=0
    for _ in range(int(stdin.readline())):
        s=stdin.readline().strip()
        if '++' in s:
            x+=1
        elif '--' in s:
            x-=1
    stdout.write(str(x))
if __name__=='__main__':
    main()
'''
#158B
'''
def main():
    from sys import stdin,stdout
    from math import ceil
    n=int(stdin.readline())
    l=sorted(list(map(int,stdin.readline().split())))
    counter=l.count(4)
    l=''.join(str(x) for x in l)
    l=l.replace('4','',counter)
    while l[-1]=='3':
        if l[0]=='1':
            l=l[1:-1]
            counter+=1
        else:
            l=l[:-1]
            counter+=1
    while l[-1]=='2':
        if len(l) > 1:
            if l[-2]=='2':
                l=l[:-2]
                counter+=1
        elif l[:2]=='1':
            l=l[2:-1]
            counter+=1
        elif l[0]=='1':
            l=''
            counter+=1
        else:
            counter+=1
    counter+=ceil(len(l)/4)
    stdout.write(str(counter))
if __name__=='__main__':
    main()
'''
#96A
'''
def main():
    from sys import stdin,stdout
    s=stdin.readline().strip()
    count=1
    flag=0
    for i in range(1,len(s)):
        if s[i]==s[i-1]:
            count+=1
            if count >=7:
                flag=1
                break
        else:
            count=1
    if flag:
        stdout.write('YES')
    else:
        stdout.write('NO')
if __name__=='__main__':
    main()
'''
#116A
'''
def main():
    from sys import stdin,stdout
    maxim=0
    total=0
    for _ in range(int(stdin.readline())):
        a,b=map(int,stdin.readline().split())
        total+=(b-a)
        if total >maxim:
            maxim=total
    stdout.write(str(maxim))
if __name__=='__main__':
    main()
'''
#112A
'''
def main():
    from sys import stdin,stdout
    s=stdin.readline().strip().lower()
    t=stdin.readline().strip().lower()
    if s==t:
        stdout.write('0')
    elif s < t:
        stdout.write('-1')
    else:
        stdout.write('1')
if __name__=='__main__':
    main()
'''
#339A
'''
def main():
    from sys import stdin,stdout
    l=list(map(str,stdin.readline().strip().split('+')))
    l.sort()
    stdout.write('+'.join(l))
if __name__=='__main__':
    main()
'''
#131A
'''

def main():
    from sys import stdin,stdout
    s=stdin.readline().strip()
    if s.isupper():
        stdout.write(s.lower())
    elif (s[0].islower() and s[1:].isupper()) or (len(s)==1 and s.islower()):
        stdout.write(s.title())
    else:
        stdout.write(s)
if __name__=='__main__':
    main()
'''
#266A
'''
def main():
    from sys import stdin,stdout
    n=int(stdin.readline())
    count=0
    s=stdin.readline().strip()
    for i in range(1,n):
        if s[i]==s[i-1]:
            count+=1
    stdout.write(str(count))
if __name__=='__main__':
    main()
'''
#133A
'''
def main():
    from sys import stdin,stdout
    s=stdin.readline().strip()
    if 'H' in s or 'Q' in s or '9' in s:
        stdout.write('YES')
    else:
        stdout.write('NO')
if __name__=='__main__':
    main()
'''
#281A
'''
def main():
    from sys import stdin,stdout
    s=stdin.readline().strip()
    stdout.write(s[0].upper()+s[1:])
if __name__=='__main__':
    main()
'''
#58A
'''
def main():
    from sys import stdin,stdout
    test='hello'
    s=stdin.readline().strip()
    while len(test) and len(s):
        if test[0]==s[0]:
            test=test[1:]
            s=s[1:]
        else:
            s=s[1:]
    if test=='':
        stdout.write('YES')
    else:
        stdout.write('NO')
if __name__=='__main__':
    main()
'''
#236A
'''
def main():
    from sys import stdin,stdout
    if len(set(stdin.readline().strip())) & 1:
        stdout.write('IGNORE HIM!')
    else:
        stdout.write('CHAT WITH HER!')
if __name__=='__main__':
    main()
'''
#467A
'''
def main():
    from sys import stdin,stdout
    count=0
    for _ in range(int(stdin.readline())):
        a,b=map(int,stdin.readline().split())
        if b-a>=2:
            count+=1
    stdout.write(str(count))
if __name__=='__main__':
    main()
'''
#148A
'''
def main():
    from sys import stdin,stdout
    k=int(stdin.readline())
    l=int(stdin.readline())
    m=int(stdin.readline())
    n=int(stdin.readline())
    d=int(stdin.readline())
    count=0
    for i in range(1,d+1):
        if i % k and i % l and i % m and i % n:
            count+=1
    stdout.write(str(d-count))
if __name__=='__main__':
    main()
'''
#263A
'''
def main():
    from sys import stdin,stdout
    for i in range(5):
        a=list(map(int,stdin.readline().split()))
        try:
            x=a.index(1)+1
            y=i+1
        except:
            g=''
    stdout.write(str(abs(x-3)+abs(y-3)))
if __name__=='__main__':
    main()
'''
#546A
'''
def main():
    from sys import stdin,stdout
    k,n,w=map(int,stdin.readline().split())
    m=(w*(w+1)*k)//2
    if m<=n:
        stdout.write('0')
    else:
        stdout.write(str(m-n))
if __name__=='__main__':
    main()
'''
#136A
'''
def main():
    from sys import stdin,stdout
    n=int(stdin.readline())
    l=list(map(int,stdin.readline().split()))
    p=[0 for _ in range(n)]
    for i in range(n):
        p[l[i]-1]=i+1
    stdout.write(' '.join(str(x) for x in p))
if __name__=='__main__':
    main()
'''
#122A
'''
def main():
    l=[]
    for i in range(4,1001):
        s=str(i)
        flag=1
        for element in s:
            if element !='4' and element !='7':
                flag=0
                break
        if flag:
            l.append(i)
    from sys import stdin,stdout
    n=int(stdin.readline())
    for i in l:
        if n%i==0:
            stdout.write('YES')
            return
    stdout.write('NO')
if __name__=='__main__':
    main()
'''
#266B
'''
def main():
    from sys import stdin,stdout
    n,x=map(int,stdin.readline().split())
    s=stdin.readline().strip()
    for _ in range(x):
        s=s.replace('BG','GB')
    stdout.write(s)
if __name__=='__main__':
    main()
'''
#271A
'''
def main():
    from sys import stdin,stdout
    n=int(stdin.readline())
    n+=1
    while True:
        if len(str(n))==len(set(str(n))):
            break
        else:
            n+=1
    stdout.write(str(n))
if __name__=='__main__':
    main()
'''
#41A
'''
def main():
    from sys import stdin,stdout
    a=stdin.readline().strip()
    b=stdin.readline().strip()
    if a==b[-1::-1]:
        stdout.write('YES')
    else:
        stdout.write('NO')
if __name__=='__main__':
    main()
'''
#160A
'''
def main():
    from sys import stdin,stdout
    n=int(stdin.readline())
    l=sorted(list(map(int,stdin.readline().split())))
    p=l[-1]
    lsum=sum(l[:-1])
    l=l[:-1]
    count=1
    while lsum >= p:
        p+=l[-1]
        lsum-=l[-1]
        l=l[:-1]
        count+=1
    stdout.write(str(count))
if __name__=='__main__':
    main()
'''
#110A
'''
def main():
    from sys import stdin,stdout
    s=stdin.readline().strip()
    k=s.count('4')+s.count('7')
    if  k==4 or k==7:
        stdout.write('YES')
    else:
        stdout.write('NO')
if __name__=='__main__':
    main()
'''
#100989A
'''
def main():
    from sys import stdin,stdout
    stdout.write(str(int(stdin.readline())+1))
if __name__=='__main__':
    main()
'''
#100989C
'''
def main():
    from sys import stdin,stdout
    count=0
    for _ in range(int(stdin.readline())):
        a,b=map(int,stdin.readline().split())
        count+=(b-a)
    stdout.write(str(count))
if __name__=='__main__':
    main()
'''
#100989D
'''
def main():
    from sys import stdin,stdout
    n,q=map(int,stdin.readline().split())
    l=sorted(list(map(int,stdin.readline().split())))
    o=[]
    for i in range(n):
        o.append(0)
    while q:
        a,b=map(str,stdin.readline().split())
        if a =='in':
            b=int(b)
            flag=0
            for i in range(n):
                if b<=l[i] and o[i]==0:
                    o[i]=1
                    flag=1
                    break
            if flag:
                stdout.write(str(i+1)+'\n')
            else:
                stdout.write('-1\n')
        else:
            b=int(b)-1
            o[b]=0
        q-=1
if __name__=='__main__':
    main()
'''
#82A
'''
def main():
    from sys import stdin, stdout
    n=int(stdin.readline())
    while n>5:
        if n&1:
            n-=5
            n//=2
        else:
            n-=4
            n//=2
    if n==1:
        stdout.write('Sheldon')
    elif n==2:
        stdout.write('Leonard')
    elif n==3:
        stdout.write('Penny')
    elif n==4:
        stdout.write('Rajesh')
    else:
        stdout.write('Howard')
if __name__=='__main__':
    main()
'''
#460A
'''
WA
def main():
    from sys import stdin,stdout
    n,m=map(int,stdin.readline().split())
    counter=n
    while n>=m:
        counter+=n//m
        n//=m
    stdout.write(str(counter))
if __name__=='__main__':
    main()
'''
#479A
'''
def main():
    from sys import stdin,stdout
    a=int(stdin.readline())
    b=int(stdin.readline())
    c=int(stdin.readline())
    maxim=a*b*c
    if a+b+c > maxim:
        maxim=a+b+c
    if (a+b)*c >maxim:
        maxim=(a+b)*c
    if a*(b+c)>maxim:
        maxim=a*(b+c)
    if a+b*c > maxim:
        maxim=a+b*c
    stdout.write(str(maxim))
if __name__=='__main__':
    main()
'''
#69A
'''
def main():
    from sys import stdin,stdout
    a,b,c=0,0,0
    for _ in range(int(stdin.readline())):
        x,y,z=map(int,stdin.readline().split())
        a+=x
        b+=y
        c+=z
    if a or b or c:
        stdout.write('NO')
    else:
        stdout.write('YES')
if __name__=='__main__':
    main()
'''
#580A
'''
def main():
    from sys import stdin,stdout
    n=int(stdin.readline())
    l=list(map(int,stdin.readline().split()))
    max_so_far=1
    counter=1
    for i in range(1,n):
        if l[i]>=l[i-1]:
            counter+=1
        else:
            max_so_far=max(max_so_far,counter)
            counter=1
    stdout.write(str(max(max_so_far,counter)))
if __name__=='__main__':
    main()
'''
#337A
'''
def main():
    from sys import stdin,stdout
    n,m=map(int,stdin.readline().split())
    li=sorted(list(map(int,stdin.readline().split())))
    minim=100000
    for i in range(m-n+1):
        sub=li[i:i+n]
        d=0
        for i in range(1,len(sub)):
            d+=sub[i]-sub[i-1]
        minim=min(minim,d)
    stdout.write(str(minim))
if __name__=='__main__':
    main()
'''
#472A
'''
def main():
    from sys import stdin,stdout
    from math import floor,sqrt
    def check(n):
        if n==2:
            return True
        elif n & 1:
            for i in range(3,floor(sqrt(n))+1):
                if n % i==0:
                    return False
            return True
        else:
            return False
    n=int(stdin.readline())
    i=4
    while True:
        #print(check(i),check(n-i))
        if check(n-i) or check(i):
            i+=1
            continue
        else:
            stdout.write(str(i)+' '+str(n-i))
            break
if __name__=='__main__':
    main()
'''
#119A
'''
def main():
    def gcd(a,b):
        if b:
            return gcd(b,a%b)
        else:
            return a
    from sys import stdin,stdout
    a,b,n=map(int,stdin.readline().split())
    flag=0
    while n > 0:
        if flag:
            n-=gcd(n,b)
            flag=0
        else:
            n-=gcd(n,a)
            flag=1
    if flag:
        stdout.write('0')
    else:
        stdout.write('1')
if __name__=='__main__':
    main()
'''
#451A
'''
def main():
    from sys import stdin,stdout
    a,b=map(int,stdin.readline().split())
    if a==1 or b==1:
        stdout.write('Akshat')
    elif min(a,b)**2 & 1:
        stdout.write('Akshat')
    else:
        stdout.write('Malvika')
if __name__=='__main__':
    main()
'''
#379A
def main():
    from sys import stdin,stdout
    a,b=map(int,stdin.readline().split())
    counter=a
    while a:
        counter+=a//b
        a//=b
    stdout.write(str(counter))
if __name__=='__main__':
    main()
