### constant

INF = 1 << 30

### main

loop do
  n = gets.to_i
  break if n == 0

  blns = n.times.map{gets.split.map(&:to_i)}
  #p blns

  dp = (n + 1).times.map{4.times.map{INF}}
  dp[0][0] = 0

  prvp = 0
  prvt = 0
  ng = nil
  
  for i in (0...n)
    pi, ti = blns[i]
    catch = false
    
    for j in (0..3)
      dij = dp[i][j]
      next if dij >= INF

      # return to home
      dt = prvp * (j + 1) + pi
      if prvt + dt <= ti
        d = dij + prvp + pi
        if dp[i + 1][1] > d
          dp[i + 1][1] = d
          catch = true
        end
      end

      # catch directly
      if j < 3
        dd = (pi - prvp).abs
        dt = dd * (j + 1)
        if prvt + dt <= ti
          d = dij + dd
          if dp[i + 1][j + 1] > d
            dp[i + 1][j + 1] = d
            catch = true
          end
        end
      end
    end
    
    if ! catch
      ng = i + 1
      break
    end
    
    prvp = pi
    prvt = ti
  end

  if ng
    puts "NG #{ng}"
  else
    min_d = dp[n].min + prvp
    puts "OK #{min_d}"
  end
end