object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN) = readLine.split(" ").map(_.toInt)
    val datA = readLine.split(" ").map(_.toLong)

    def recFunc(sum: Long, height: Long, idx: Int): Long = {
      if (idx == datA.length) sum
      else {
        if (datA(idx) > height) recFunc(sum, datA(idx), idx + 1)
        else recFunc(sum + (height - datA(idx)), height, idx + 1)
      }
    }
    val ans = recFunc(0, 0, 0)
    println(ans)
  }
}
