import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._
  loop()
  @tailrec def loop(): Unit = {
    val n = readInt()
    if (n == 0) return
    val balloons = Array.fill(n){
      val Array(p, t) = readLine.trim.split(' ').map(_.toInt)
      Balloon(p, t)
    }
    val memo = Array.fill(n){Array.fill(4){None: Option[Result]}}
    search(0, VehicleState(0, 0, 0, 0))(balloons, memo) match {
      case Success(len) ⇒
        println(s"OK $len")
      case Fail(pos) ⇒
        println(s"NG ${pos + 1}")
    }
    loop()
  }
  case class Balloon(position: Int, time: Int)
  def search(count: Int, vehicle: VehicleState)(implicit balloons: Array[Balloon], memo: Array[Array[Option[Result]]]): Result = {
    if (count == balloons.length) return Success(vehicle.position)
    memo(count)(vehicle.balloonCount) match {
      case Some(e) ⇒ e
      case None ⇒
        val res = vehicle.move(balloons(count)).map(v ⇒ search(count + 1, v).mapSuccess(_ + v.prevMove)).getOrElse(Fail(count)).accumulate(vehicle.moveWithRelayToHouse(balloons(count)).map(v ⇒ search(count + 1, v).mapSuccess(_ + v.prevMove)).getOrElse(Fail(count)))
        memo(count)(vehicle.balloonCount) = Some(res)
        res
    }
  }
  case class VehicleState(position: Int, time: Int, balloonCount: Int, prevMove: Int) {
    def move(to: Balloon): Option[VehicleState] = {
      //System.err.println(s"expected ${to.time}, actual ${math.abs(position - to.position) * (balloonCount + 1) + time}")
      if (balloonCount < 3 && to.time >= math.abs(position - to.position) * (balloonCount + 1) + time) Some(VehicleState(to.position, to.time, balloonCount + 1, math.abs(position - to.position)))
      else None
    }
    def moveWithRelayToHouse(to: Balloon): Option[VehicleState] = {
      //System.err.println(s"Relay expected ${to.time}, actual ${to.position + position * (balloonCount + 1) + time}")
      if (to.time >= to.position + position * (balloonCount + 1) + time) Some(VehicleState(to.position, to.time, 1, to.position + position))
      else None
    }
  }
  sealed trait Result {
    def accumulate(result: Result): Result
    def mapSuccess(func: Int ⇒ Int): Result = this
  }
  case class Success(length: Int) extends Result {
    override def accumulate(result: Result): Result = {
      result match {
        case Success(r) ⇒ Success(math.min(length, r))
        case Fail(_) ⇒ this
      }
    }
    override def mapSuccess(func: Int ⇒ Int): Result = Success(func(length))
  }
  case class Fail(failPosition: Int) extends Result {
    override def accumulate(result: Result): Result = {
      result match  {
        case Fail(f) ⇒ Fail(math.max(failPosition, f))
        case Success(_) ⇒ result
      }
    }
  }
}
