n = int(input()) k = int(input()) cnt = 0 ret = 0 while n > 0 : ret = ret + n cnt = cnt + n n = cnt / k cnt = cnt % k print (ret)