#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
#define INF (1e9)
#define N 41
#define B 4

int main(){
  int n,p[N],t[N],dp[N][B],tim,pos,ans;
  while(1){
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>p[i]>>t[i];
    for(int i=0;i<N;i++)
      for(int j=0;j<B;j++) dp[i][j]=INF;
    dp[0][0]=tim=pos=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<B;j++){
	if(dp[i][j]==INF) continue;
	if(i>=1&&j>=1&&t[i-1]+p[i-1]*(j+1)+p[i]<=t[i])
	  dp[i+1][1]=min(dp[i+1][1],dp[i][j]+p[i-1]+p[i]);
	if(j<=2&&tim+abs(p[i]-pos)*(j+1)<=t[i])
	  dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+abs(p[i]-pos));
      }
      tim=t[i],pos=p[i];
    }
    ans=INF;
    for(int i=0;i<B;i++) ans=min(ans,dp[n][i]);
    if(ans!=INF) cout<<"OK "<<ans+p[n-1]<<endl;
    else{
      for(int i=0;i<=n;i++){
	int flag=1;
	for(int j=0;j<B;j++)
	  if(dp[i][j]!=INF) flag=0;
	if(flag){
	  cout<<"NG "<<i<<endl;
	  break;
	}
      }
    }
  }
  return 0;
}