loop {
	n = gets.to_i
	break if n == 0
	baloons = (1..n).map {
		gets.split.map &:to_i 		
	}

	if baloons[0].inject(:>)
		puts 'NG 1'
		next
	end

	baloons << [0, baloons[-1][1] + baloons[-1][0] * 5]
	x0, t0 = baloons.shift

	min_dist = [[x0, Float::INFINITY, Float::INFINITY], []]
	itr = 0
	baloons.each{|x, t|
		min_dist[1][0] = (0..2).map{|i|
			x0 * (i+2) + x <= t - t0 ? min_dist[0][i] + x0 + x : Float::INFINITY
		}.min

		min_dist[1][1] = (x - x0).abs * 2 <= t - t0 ? min_dist[0][0] + (x - x0).abs : Float::INFINITY
		min_dist[1][2] = (x - x0).abs * 3 <= t - t0 ? min_dist[0][1] + (x - x0).abs : Float::INFINITY
		
		break if min_dist[1] == [Float::INFINITY] * 3
		x0, t0 = x, t
		min_dist << min_dist.shift
		itr += 1
	}
	if itr < baloons.size
		puts "NG #{itr+2}"
	else
		puts "OK #{min_dist[0].min}"
	end
}