def bsearch_first(l, r, &pred)
    return nil if l > r
    c = (l + r) / 2 
    if pred[c]
        bsearch_first(l, c-1, &pred) || c
    else
        bsearch_first(c+1, r, &pred)
    end
end

n, k = gets.split.map(&:to_i)
x = 0
loop do
    n -= 1
    break if n == 0
    y = bsearch_first(x, (1 + x) * k) {|z| z - (1 + z / k) >= x}
    x = y
end
puts x
