object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val items = Array.tabulate(n){_ ⇒
    val Array(v, h) = readLine.trim.split(' ').map(_.toInt)
    Item(v, h)
  }
  val itemInfo = new ItemInfo(items)
  val events = List.tabulate(m){_ ⇒
    val Array(t, s) = readLine.trim.split(' ').map(_.toInt)
    (t, s)
  }
  val maxStrength = events.map{_._2}.max

  println(
    search(events, itemInfo, maxStrength) match {
      case Some(r) ⇒ r
      case None ⇒ -1
    }
  )

  def search(events: List[(Int, Int)], itemInfo: ItemInfo, maxStrength: Int, confirmedOnus: Int = 0, currentWholePower: Int = 0, prevBuy: Int = -1, prevCanBuy: Int = -1, lastTime: Int = 0): Option[Int] = {
    events match {
      case Nil ⇒ Some(lastTime - itemInfo.costToBuyTo(prevBuy))
      case (t, s)::tail ⇒
        if (currentWholePower - confirmedOnus < s){
          val whileMax = itemInfo.mustBuy(maxStrength + confirmedOnus)
          if (itemInfo.indices.contains(whileMax) && itemInfo.costToBuyTo(whileMax) <= t) search(tail, itemInfo, maxStrength, confirmedOnus, maxStrength + confirmedOnus, whileMax, -1, t)
          else {
            val mustBuy = itemInfo.mustBuy(s + confirmedOnus)
            val canBuy = itemInfo.maxItemCanBuy(t)
            if (mustBuy > canBuy) None
            else {
              val minOnus = (mustBuy to canBuy).minBy{it ⇒ itemInfo.onusStopBuyTo(it)}
              if (minOnus <= prevCanBuy){
                search(tail, itemInfo, maxStrength, confirmedOnus, itemInfo.wholeStrengthTo(minOnus), minOnus, prevCanBuy, t)
              }else {
                search(tail, itemInfo, maxStrength, confirmedOnus + (if (prevBuy >= 0) itemInfo.onusStopBuyTo(prevBuy) else 0), itemInfo.wholeStrengthTo(minOnus), minOnus, canBuy, t)
              }
            }
          }
        }else {
          search(tail, itemInfo, maxStrength, confirmedOnus, currentWholePower, prevBuy, prevCanBuy, t)
        }
    }
  }
  class ItemInfo(private val items: Array[Item]) {
    //cost(i) => 0 to i までのアイテムの購入コストの合計
    private val cost = items.map{_.cost}.also{it ⇒ for (i ← 1 until it.length) it(i) += it(i - 1)}
    //bonus(i) => items(i)とitems(i + 1)を同時に勝った場合のボーナス
    private val bonus = items.map{_.benefit}.also{it ⇒
      for (i ← 1 until it.length)
        it(i - 1) = abs(it(i) - it(i - 1))
      it(it.length - 1) = 0
    }
    //strength(i) => 0 to iまでのアイテムをすべて一度に買った場合の強さの増加分
    private val strength = items.map{_.benefit}.also{it ⇒ for (i ← 1 until it.length) it(i) += it(i - 1) + bonus(i - 1)}
    def maxItemCanBuy(money: Int): Int = upperBound(cost, money) - 1
    def mustBuy(strong: Int): Int = lowerBound(strength, strong)
    def wholeStrengthTo(item: Int): Int = strength(item)
    def onusStopBuyTo(item: Int): Int = bonus(item)
    def costToBuyTo(item: Int): Int = cost(item)
    def indices = items.indices
  }
  def upperBound[T](array: Array[T], value: T)(implicit ordering: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ordering.compare(array(mid), value) <= 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  def lowerBound[T](array: Array[T], value: T)(implicit ordering: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ordering.compare(array(mid), value) < 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }

  case class Item(cost: Int, benefit: Int)

  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
