function parseInput(input) {
  const values = []
  input.split('\n').forEach(row => {
    const list = row.split(' ')
    list.forEach(v => values.push(v))
  })

  return values
}

function getInput() {
  const dummy = ``
  return parseInput(dummy || require('fs').readFileSync('/dev/stdin', 'utf8'))
}

;(function main() {
  const input = getInput()
  var N = +input[0]
  const K = +input[1]



  var count = 0
  while (N >= 0) {
    count++
    N -= Math.pow(K , count)
  }

  const c = Math.pow(10, 9) + 7
  console.log(count % c)
})()
