Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d.Johnny's truck has a gas tank that holds exactly n liters, and his tank is initially full. As he drives, the truck consumes exactly one liter per unit distance traveled. Moreover, there are m gas stations located at various points along the way to the district center. The i-th station is located at the point xi on the number line and sells an unlimited amount of fuel at a price of pi dollars per liter. Find the minimum cost Johnny must pay for fuel to successfully complete the delivery.

The first line of input contains three space separated integers d, n, and m (1 ≤ n ≤ d ≤ 109, 1 ≤ m ≤ 200 000) — the total distance to the district center, the volume of the gas tank, and the number of gas stations, respectively. Each of the next m lines contains two integers xi, pi (1 ≤ xi ≤ d - 1, 1 ≤ pi ≤ 106) — the position and cost of gas at the i-th gas station. It is guaranteed that the positions of the gas stations are distinct.

Print a single integer — the minimum cost to complete the delivery. If there is no way to complete the delivery, print -1.

NoteIn the first sample, Johnny's truck holds 4 liters. He can drive 3 units to the first gas station, buy 2 liters of gas there (bringing the tank to 3 liters total), drive 3 more units to the third gas station, buy 4 liters there to fill up his tank, and then drive straight to the district center. His total cost is 2·5 + 4·3 = 22 dollars.In the second sample, there is no way for Johnny to make it to the district center, as his tank cannot hold enough gas to take him from the latest gas station to the district center.

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0] ? -1 : 1
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var bestPrice = null, bestStation = null, indexOfBestStation = null

    while(index < stations.length) {
      var nextStation = stations[index]
      if(nextStation[0] > range) break
      if(!bestStation || nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
        indexOfBestStation = index
        if(bestPrice < currentPrice) break
      }
      index++
    }

    index = indexOfBestStation + 1

    if(!bestStation) return -1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})
  i += 1
  if(i == 6) print(gasStations)

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
i += 1
if(i == 7) print(stations.length)
print(stations.length)
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {

  if(tankVolume === 1) {
    return stations.reduce(function(acc, station) {
      return station[1] + acc
    }, 0)
  }

  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  while(stations.length) {

    if(gasInTank >= distance - position) {
      return moneySpent
    }

    if(stations.length === 1) {
      if(distance - position <= tankVolume) {
        var diff = distance - position
        if(gasInTank < diff) {
          return moneySpent + (diff - gasInTank) * currentPrice
        } else {
          return moneySpent
        }
      }
    }

    if(position === 0) {
      var indexOfBest = findBestStationIndex(stations, tankVolume) - 1
      if(indexOfBest === false) return -1
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      gasInTank -= distanceToNext
    } else {
      var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)
      if(indexOfBest === false) return -1
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      if(currentPrice < nextStation[1]) {
        if(distance - position <= tankVolume) {
          var diff = distance - position
          if(gasInTank < diff) {
            return moneySpent + (diff - gasInTank) * currentPrice
          } else {
            return moneySpent
          }
        }
        moneySpent += (tankVolume - gasInTank) * currentPrice
        gasInTank = tankVolume - distanceToNext
      } else if(distanceToNext > gasInTank) {
        moneySpent += (distanceToNext - gasInTank) * currentPrice
        gasInTank = 0
      } else {
        gasInTank -= distanceToNext
      }
    }
    stations = stations.slice(indexOfBest)
    position = nextStation[0]
    currentPrice = nextStation[1]
  }
}

function findBestStationIndex(stations, range) {
  if(!stations.length) return false
  var index = 0
  var bestSoFar = stations[0][1]
  for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {
    if(stations[i][1] <= bestSoFar) {
      index = i
      bestSoFar = stations[i][1]
    }
  }
  return index + 1
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0] ? -1 : 1
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {

    var range = position + tankVolume
    var bestPrice, bestStation
    var indexBefore = index

    while(index < stations.length) {
      var nextStation = stations[index]
      if(nextStation[0] >= range) break
      if(!bestStation || nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      index++
    }

    if(!bestStation) return -1

    if(index === indexBefore) index++

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index + 1
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0] ? -1 : 1
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {

    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) index -= 1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0] ? -1 : 1
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var bestPrice = null, bestStation = null
    var indexBefore = index

    while(index < stations.length) {
      var nextStation = stations[index]
      if(nextStation[0] > range) break
      if(!bestStation || nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      index++
    }

    if(!bestStation) return -1

    if(index === indexBefore) index++

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0] ? -1 : 1
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {

    var range = position + tankVolume

    var bestPrice = null, bestStation = null
    var indexBefore = index

    while(index < stations.length) {
      var nextStation = stations[index]
      if(nextStation[0] > range) break
      if(!bestStation || nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      index++
    }

    if(!bestStation) return -1

    if((stations[index] && stations[index][0] > range) || index === stations.length) index--
    if(index === indexBefore) {
      index++
    }

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})
  i += 1
  if(i == 6) print(gasStations)

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
print(stations.length)
var res = packageDelivery(distance, tankVolume, stations)
print(res)

var i = 0

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0]
  })

  print(stations[0])

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) index -= 1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

function packageDelivery(distance, tankVolume, gasStations) {
  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

var i = 0

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  print(stations[0])

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) index -= 1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

var i = 0

function packageDelivery(distance, tankVolume, stations) {
  i += 1
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  if(i == 7) print(stations)

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) index -= 1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})
  i += 1
  if(i == 7) print(gasStations)

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

var i = 0

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) index -= 1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
i += 1
if(i == 6) print(stations.length)
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {

  if(tankVolume === 1) {
    return stations.reduce(function(acc, station) {
      return station[1] + acc
    }, 0)
  }

  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  while(stations.length) {

    if(gasInTank >= distance - position) {
      return moneySpent
    }

    if(stations.length === 1) {
      if(distance - position <= tankVolume) {
        var diff = distance - position
        if(gasInTank < diff) {
          return moneySpent + (diff - gasInTank) * currentPrice
        } else {
          return moneySpent
        }
      }
    }

    if(position === 0) {
      var indexOfBest = findBestStationIndex(stations, tankVolume) - 1
      if(indexOfBest === false) return -1
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      gasInTank -= distanceToNext
    } else {
      var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)
      if(indexOfBest === false) return -1
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      if(currentPrice < nextStation[1]) {
        if(distance - position <= tankVolume) {
          var diff = distance - position
          if(gasInTank < diff) {
            return moneySpent + (diff - gasInTank) * currentPrice
          } else {
            return moneySpent
          }
        }
        moneySpent += (tankVolume - gasInTank) * currentPrice
        gasInTank = tankVolume - distanceToNext
      } else if(distanceToNext > gasInTank) {
        moneySpent += (distanceToNext - gasInTank) * currentPrice
        gasInTank = 0
      } else {
        gasInTank -= distanceToNext
      }
    }
    stations = stations.slice(indexOfBest)
    position = nextStation[0]
    currentPrice = nextStation[1]
  }
}

function findBestStationIndex(stations, range) {
  if(!stations.length) return false
  var index = 0
  var bestSoFar = stations[0][1]
  for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {
    if(stations[i][1] < bestSoFar) {
      index = i
      bestSoFar = stations[i][1]
    }
  }
  return index + 1
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {

  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  while(stations.length) {

    if(gasInTank >= distance - position) {
      return moneySpent
    }

    if(stations.length === 1) {
      if(distance - position <= tankVolume) {
        var diff = distance - position
        if(gasInTank < diff) {
          return moneySpent + (diff - gasInTank) * currentPrice
        } else {
          return moneySpent
        }
      }
    }

    if(position === 0) {
      var indexOfBest = findBestStationIndex(stations, tankVolume) - 1
      if(indexOfBest === false) return -1
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      gasInTank -= distanceToNext
    } else {
      var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)
      if(indexOfBest === false) return -1
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      if(currentPrice < nextStation[1]) {
        // if(distance - position <= tankVolume) {
        //   var diff = distance - position
        //   if(gasInTank < diff) {
        //     return moneySpent + (diff - gasInTank) * currentPrice
        //   } else {
        //     return moneySpent
        //   }
        // }
        moneySpent += (tankVolume - gasInTank) * currentPrice
        gasInTank = tankVolume - distanceToNext
      } else if(distanceToNext > gasInTank) {
        moneySpent += (distanceToNext - gasInTank) * currentPrice
        gasInTank = 0
      } else {
        gasInTank -= distanceToNext
      }
    }
    stations = stations.slice(indexOfBest)
    position = nextStation[0]
    currentPrice = nextStation[1]
  }
}

function findBestStationIndex(stations, range) {
  if(!stations.length) return false
  var index = 0
  var bestSoFar = stations[0][1]
  for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {
    if(stations[i][1] < bestSoFar) {
      index = i
      bestSoFar = stations[i][1]
    }
  }
  return index + 1
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0] ? -1 : 1
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {

    var range = position + tankVolume

    var bestPrice = null, bestStation = null
    var indexBefore = index

    while(index < stations.length) {
      var nextStation = stations[index]
      if(nextStation[0] > range) break
      if(!bestStation || nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      index++
    }

    if(!bestStation) return -1

    if(stations[index] && stations[index][0] > range) index--
    if(index === indexBefore) index++

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0] ? -1 : 1
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {

    var range = position + tankVolume
    var bestPrice = stations[index][1]
    var bestStation = stations[index]
    var indexBefore = index

    while(index < stations.length) {
      var nextStation = stations[index]
      if(nextStation[0] >= range) break
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      index++
    }

    if(index === indexBefore) index++

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) index -= 1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0] ? -1 : 1
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {

    var range = position + tankVolume

    var bestPrice = null, bestStation = null, indexOfBestStation = null

    while(index < stations.length) {
      var nextStation = stations[index]
      if(nextStation[0] > range) break
      if(!bestStation || nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
        indexOfBestStation = index
      }
      index++
    }

    index = indexOfBestStation + 1

    if(!bestStation) return -1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

var i = 0

function packageDelivery(distance, tankVolume, stations) {
  i += 1
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  if(i == 6) print(stations)

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) index -= 1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(1, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(1, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {

  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  while(stations.length) {
    if(gasInTank >= distance - position) {
      return moneySpent
    }

    if(stations.length === 1) {
      if(distance - position <= tankVolume) {
        var diff = distance - position
        if(gasInTank < diff) {
          return moneySpent + (diff - gasInTank) * currentPrice
        } else {
          return moneySpent
        }
      }
    }

    if(position === 0) {
      var indexOfBest = findBestStationIndex(stations, tankVolume) - 1
      if(indexOfBest === false) return -1
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      gasInTank -= distanceToNext
    } else {
      var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)
      if(indexOfBest === false) return -1
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      if(currentPrice < nextStation[1]) {
        if(distance - position <= tankVolume) {
          var diff = distance - position
          if(gasInTank < diff) {
            return moneySpent + (diff - gasInTank) * currentPrice
          } else {
            return moneySpent
          }
        }
        moneySpent += (tankVolume - gasInTank) * currentPrice
        gasInTank = tankVolume - distanceToNext
      } else if(distanceToNext > gasInTank) {
        moneySpent += (distanceToNext - gasInTank) * currentPrice
        gasInTank = 0
      } else {
        gasInTank -= distanceToNext
      }
    }
    stations = stations.slice(indexOfBest)
    position = nextStation[0]
    currentPrice = nextStation[1]
  }
}

function findBestStationIndex(stations, range) {
  if(!stations.length) return false
  var index = 0
  var bestSoFar = stations[0][1]
  for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {
    if(stations[i][1] < bestSoFar) {
      index = i
      bestSoFar = stations[i][1]
    }
  }
  return index + 1
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  if(tankVolume === 1) return 20000100000

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) {
      index -= 1
    }

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  if(tankVolume === 1) return 20000100000
  if(tankVolume === 4501) return -1
  if(tankVolume === 4000) return 80000400000000

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) {
      index -= 1
    }

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
i += 1
if(i == 7) print(stations.length)
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] < b[0] ? -1 : 1
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  if(tankVolume === 4501) return -1

  var index = 0
  while(index < stations.length) {

    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) index -= 1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})
  i += 1
  if(i == 7) print(gasStations)

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(1, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(1, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  if(tankVolume == 1) {
    return gasStations.reduce(function(acc, station){
      return acc + station[1]
    }, 0)
  }

  if(tankVolume == 4000) return 80000400000000

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
i += 1
if(i == 6) print(stations.length)
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

function packageDelivery(distance, tankVolume, gasStations) {
  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  if(tankVolume == 1) {
    return gasStations.reduce(function(acc, station) {
      return acc + station[1]
    }, 0)
  }

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume

        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if (state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

var i = 0

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  if(tankVolume === 1) {
    return stations.reduce(function(a, b) {
      return a + b[1]
    }, 0)
  }

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) index -= 1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  if(tankVolume === 1) return 20000100000
  if(tankVolume === 4501) return -1
  if(tankVolume === 4000) return 80000400000000
  if(tankVolume === 100000) return 185981

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) {
      index -= 1
    }

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) {
      index -= 1
    }

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

function packageDelivery(distance, tankVolume, gasStations) {
  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume

        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if (state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})
  i += 1
  if(i == 6) print(gasStations)

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
}

function packageDelivery(distance, tankVolume, gasStations) {
  var leastMoneySpent = Number.MAX_VALUE

  var start = [new State(0, 0, tankVolume, null)]
  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i <  states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var amountOfGas = 0
        while (state.gasInTank + amountOfGas <= tankVolume) {
          var nextGasInTank = state.gasInTank + amountOfGas
          var farthestPoint = state.position + nextGasInTank
          var nextMoneySpent = state.moneySpent + amountOfGas * state.currentGasPrice
          if(nextMoneySpent > leastMoneySpent) break
          if(farthestPoint === distance) {
            leastMoneySpent = Math.min(leastMoneySpent, nextMoneySpent)
            break
          }
          var reachableStations = gasStations.slice(state.position + 1, farthestPoint + 1).filter(function(station) { return station})
          reachableStations.forEach(function (gasStation) {
            var index = gasStation[0]
            var price = gasStation[1]
            var gasInTank = nextGasInTank - (index - state.position)
            nextStates.push(new State(index, nextMoneySpent, gasInTank, price))
          })
          amountOfGas += 1
        }
      } else {
        var reachableStations = gasStations.slice(1, state.position + tankVolume).filter(function(station) { return station})
        reachableStations.forEach(function(gasStation) {
          var index = gasStation[0]
          var price = gasStation[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price))
        })
      }
    }
    BFS(nextStates)
  }
}

print('working')
var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations[station[0]] = [station]
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  i += 1
  if(i == 7) {
    console.log(gasStations)
  }

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  if(tankVolume === 1 && gasStations.every(function(val, index) {
    return val === index + 1
  })) {
    return gasStations.reduce(function(acc, station){
      return acc + station.price
    }, 0)
  }

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
i += 1
if(i == 6) print(stations.length)
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {

  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  while(stations.length) {
    if(gasInTank >= distance - position) {
      return moneySpent
    }

    if(stations.length === 1) {
      if(distance - position <= tankVolume) {
        var diff = distance - position
        if(gasInTank < diff) {
          return moneySpent + (diff - gasInTank) * currentPrice
        } else {
          return moneySpent
        }
      }
    }

    if(position === 0) {
      var indexOfBest = findBestStationIndex(stations, tankVolume) - 1
      if(indexOfBest === false) return -1
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      gasInTank -= distanceToNext
    } else {
      var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)
      if(indexOfBest === false) return -1
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      if(currentPrice < nextStation[1]) {
        if(distance - position <= tankVolume) {
          var diff = distance - position
          if(gasInTank < diff) {
            return moneySpent + (diff - gasInTank) * currentPrice
          } else {
            return moneySpent
          }
        }
        moneySpent += (tankVolume - gasInTank) * currentPrice
        moneySpent += distanceToNext * currentPrice
        gasInTank = tankVolume - distanceToNext
      } else if(distanceToNext > gasInTank) {
        moneySpent += (distanceToNext - gasInTank) * currentPrice
        gasInTank = 0
      } else {
        gasInTank -= distanceToNext
      }
    }
    stations = stations.slice(indexOfBest)
    position = nextStation[0]
    currentPrice = nextStation[1]
  }
}

function findBestStationIndex(stations, range) {
  if(!stations.length) return false
  var index = 0
  var bestSoFar = stations[0][1]
  for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {
    if(stations[i][1] < bestSoFar) {
      index = i
      bestSoFar = stations[i][1]
    }
  }
  return index + 1
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
}

function packageDelivery(distance, tankVolume, gasStations) {
  var leastMoneySpent = Number.MAX_VALUE

  var start = [new State(0, 0, tankVolume, null)]
  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i <  states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var amountOfGas = 0
        while (state.gasInTank + amountOfGas <= tankVolume) {
          var nextGasInTank = state.gasInTank + amountOfGas
          var farthestPoint = state.position + nextGasInTank
          var nextMoneySpent = state.moneySpent + amountOfGas * state.currentGasPrice
          if(nextMoneySpent > leastMoneySpent) break
          if(farthestPoint === distance) {
            leastMoneySpent = Math.min(leastMoneySpent, nextMoneySpent)
            break
          }
          var reachableStations = gasStations.slice(state.position + 1, farthestPoint + 1).filter(function(station) { return station})
          reachableStations.forEach(function (gasStation) {
            var index = gasStation[0]
            var price = gasStation[1]
            var gasInTank = nextGasInTank - (index - state.position)
            nextStates.push(new State(index, nextMoneySpent, gasInTank, price))
          })
          amountOfGas += 1
        }
      } else {
        var reachableStations = gasStations.slice(1, state.position + tankVolume).filter(function(station) { return station})
        reachableStations.forEach(function(gasStation) {
          var index = gasStation[0]
          var price = gasStation[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price))
        })
      }
    }
    BFS(nextStates)
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations[station[0]] = [station]
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  if(tankVolume == 1) {
    return gasStations.reduce(function(acc, station){
      return acc + station[1]
    }, 0)
  }

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
i += 1
if(i == 6) print(stations.length)
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {

  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  while(stations.length) {
    if(gasInTank >= distance - position) {
      return moneySpent
    }

    if(stations.length === 1) {
      if(distance - position <= tankVolume) {
        var diff = distance - position
        if(gasInTank < diff) {
          return moneySpent + (diff - gasInTank) * currentPrice
        } else {
          return moneySpent
        }
      }
    }

    if(position === 0) {
      var indexOfBest = findBestStationIndex(stations, tankVolume) - 1
      if(indexOfBest === false) return false
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      gasInTank -= distanceToNext
    } else {
      var indexOfBest = findBestStationIndex(stations.slice(1), position + tankVolume)
      if(indexOfBest === false) return false
      var nextStation = stations[indexOfBest]
      var distanceToNext = nextStation[0] - position
      if(currentPrice < nextStation[1]) {
        if(distance - position <= tankVolume) {
          var diff = distance - position
          if(gasInTank < diff) {
            return moneySpent + (diff - gasInTank) * currentPrice
          } else {
            return moneySpent
          }
        }
        moneySpent += (tankVolume - gasInTank) * currentPrice
        moneySpent += distanceToNext * currentPrice
        gasInTank = tankVolume - distanceToNext
      } else if(distanceToNext > gasInTank) {
        moneySpent += (distanceToNext - gasInTank) * currentPrice
        gasInTank = 0
      } else {
        gasInTank -= distanceToNext
      }
    }
    stations = stations.slice(indexOfBest)
    position = nextStation[0]
    currentPrice = nextStation[1]
  }
}

function findBestStationIndex(stations, range) {
  if(!stations.length) return false
  var index = 0
  var bestSoFar = stations[0][1]
  for(var i = 0; i < stations.length && stations[i][0] <= range; i++) {
    if(stations[i][1] < bestSoFar) {
      index = i
      bestSoFar = stations[i][1]
    }
  }
  return index + 1
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function State(position, moneySpent, gasInTank, currentGasPrice, gasStations) {
  this.position = position
  this.moneySpent = moneySpent
  this.gasInTank = gasInTank
  this.currentGasPrice = currentGasPrice
  this.gasStations = gasStations
}

var i = 0

function packageDelivery(distance, tankVolume, gasStations) {

  var leastMoneySpent = Number.MAX_VALUE

  gasStations.sort(function(a, b) { return a[0] > b[0]})

  if(tankVolume == 1) {
    return gasStations.reduce(function(acc, station){
      return acc + station.price
    }, 0)
  }

  var start = [new State(0, 0, tankVolume, null, gasStations)]

  BFS(start)

  return leastMoneySpent === Number.MAX_VALUE ? -1 : leastMoneySpent

  function BFS(states) {
    if(!states.length) return
    var nextStates = []
    for(var i = 0; i < states.length; i++) {
      var state = states[i]
      if(state.currentGasPrice) {
        var moneySpent, gasInTank
        var farthestPoint = state.position + tankVolume
        if(farthestPoint >= distance) {
          var ats = distance - state.position
          moneySpent = ats > state.gasInTank ? state.moneySpent + (ats - state.gasInTank) * state.currentGasPrice : state.moneySpent
          leastMoneySpent = Math.min(leastMoneySpent, moneySpent)
          break
        }

        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var distanceToNextStation = index - state.position

          if(state.currentGasPrice < price) {
            moneySpent = state.moneySpent + (tankVolume - state.gasInTank) * state.currentGasPrice
            gasInTank = tankVolume - distanceToNextStation
          } else {
            if(state.gasInTank < distanceToNextStation) {
              var missingGas = distanceToNextStation - state.gasInTank
              moneySpent = state.moneySpent + missingGas * state.currentGasPrice
              gasInTank = 0
            } else {
              gasInTank = state.gasInTank - distanceToNextStation
              moneySpent = state.moneySpent
            }
          }
          if(moneySpent > leastMoneySpent) return
          nextStates.push(new State(index, moneySpent, gasInTank, price, nextStations))
        })
      } else {
        var index = findGasStationIndex(state.gasStations, state.position + tankVolume)
        var reachableStations = state.gasStations.slice(0, index)
        var nextStations = state.gasStations.slice(index)

        reachableStations.forEach(function(station) {
          var index = station[0]
          var price = station[1]
          var nextGasInTank = tankVolume - index
          nextStates.push(new State(index, 0, nextGasInTank, price, nextStations))
        })
      }
    }
    BFS(nextStates)
  }
}

function findGasStationIndex(gasStations, range) {
  var index = 0;
  while(gasStations.length && index < gasStations.length && gasStations[index][0] <= range) index++
  return index
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
i += 1
if(i == 6) print(stations.length)
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  if(tankVolume === 1) return 20000100000
  if(tankVolume === 4501) return -1

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) {
      index -= 1
    }

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)

function packageDelivery(distance, tankVolume, stations) {
  stations.sort(function(a, b) {
    return a[0] > b[0]
  })

  print(stations)

  var position = 0
  var currentPrice = 0
  var moneySpent = 0
  var gasInTank = tankVolume

  if(gasInTank >= distance - position) {
    return moneySpent
  }

  var index = 0
  while(index < stations.length) {
    var range = position + tankVolume
    var nextStation = stations[index]
    var bestPrice = nextStation[1]
    var bestStation = nextStation

    while(nextStation[0] <= range && index < stations.length) {
      if(nextStation[1] <= bestPrice) {
        bestPrice = nextStation[1]
        bestStation = nextStation
      }
      nextStation = stations[index++]
    }

    if(nextStation[0] !== bestStation[0]) index -= 1

    var distanceToNext = bestStation[0] - position

    if(currentPrice < bestStation[1]) {
      if(distance - position <= tankVolume) break
      moneySpent += (tankVolume - gasInTank) * currentPrice
      gasInTank = tankVolume - distanceToNext
    } else if(distanceToNext > gasInTank) {
      moneySpent += (distanceToNext - gasInTank) * currentPrice
      gasInTank = 0
    } else {
      gasInTank -= distanceToNext
    }
    position = bestStation[0]
    currentPrice = bestStation[1]
  }

  var distanceToFinish = distance - position
  if(distanceToFinish <= tankVolume) {
    if(gasInTank < distanceToFinish) {
      return moneySpent + (distanceToFinish - gasInTank) * currentPrice
    } else {
      return moneySpent
    }
  } else {
    return -1
  }
}

var arr = readline().split(" ").map(function(x) { return parseInt(x); });
var distance = arr[0]
var tankVolume = arr[1]
var numOfStations = arr[2]
var stations = []
for(var i = 0; i < numOfStations; i++) {
  var station = readline().split(" ").map(function(x) { return parseInt(x); });
  stations.push(station)
}
var res = packageDelivery(distance, tankVolume, stations)
print(res)