object Main extends App {
  import scala.io.StdIn._
  val mod = 1000000007L
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val notExists = calNotExists(n, m)
  println(
    (exp(n)
      + mod
      - notExists)
      % mod
  )
  def exp(e: Int): Long = {
    e match {
      case 0 ⇒ 1
      case 1 ⇒ 2
      case _ ⇒ exp(e / 2).let(it ⇒ it * it * exp(e % 2)) % mod
    }
  }
  def calNotExists(size: Int, m: Int): Long = {
    val result = Array.tabulate(size + 1){_ ⇒ 0L}
    result(0) = 1
    for (i ← result.indices.tail){
      if (i < m) result(i) = (result(i - 1) * 2) % mod
      else if (i == m) result(i) = (result(i - 1) * 2 - 1) % mod
      else result(i) = (result(i - 1) * 2 - result(i - m - 1) + mod) % mod
    }
    result.last
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}
