//Hello. I'm Peter.
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double ld;
#define peter cout<<"i am peter"<<endl
#define input freopen("data.txt","r",stdin)
#define randin srand((unsigned int)time(NULL))
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define gsize(a) (int)a.size()
#define len(a) (int)strlen(a)
#define slen(s) (int)s.length()
#define pb(a) push_back(a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_minus1(a) memset(a,-1,sizeof(a))
#define clr_INT(a) memset(a,INT,sizeof(a))
#define clr_true(a) memset(a,true,sizeof(a))
#define clr_false(a) memset(a,false,sizeof(a))
#define clr_queue(q) while(!q.empty()) q.pop()
#define clr_stack(s) while(!s.empty()) s.pop()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define dep(i, a, b) for (int i = a; i > b; i--)
#define repin(i, a, b) for (int i = a; i <= b; i++)
#define depin(i, a, b) for (int i = a; i >= b; i--)
#define pi acos(-1.0)
#define eps 1e-6
#define MOD 1000000007
#define MAXN
#define N 1024
#define M
struct Data{
    int p,t;
}data[N];
int n;
int dp[N][4];
int main(){
//    input;
    clr(data);
    clr(dp);
    while(~scanf("%d",&n) && n){
        repin(i,1,n){
            scanf("%d %d",&data[i].p,&data[i].t);
        }
        repin(i,1,n){
            repin(j,1,3){
                dp[i][j]=INT;
            }
        }
        repin(i,1,n){
            //j==1;
            if(dp[i-1][1]!=INT){
                int times=2*data[i-1].p+data[i].p;
                if(data[i-1].t+times<=data[i].t){
                    dp[i][1]=min(dp[i][1],dp[i-1][1]+data[i-1].p+data[i].p);
                }
            }
            if(dp[i-1][2]!=INT){
                int times=3*data[i-1].p+data[i].p;
                if(data[i-1].t+times<=data[i].t){
                    dp[i][1]=min(dp[i][1],dp[i-1][2]+data[i-1].p+data[i].p);
                }
            }
            if(dp[i-1][3]!=INT){
                int times=4*data[i-1].p+data[i].p;
                if(data[i-1].t+times<=data[i].t){
                    dp[i][1]=min(dp[i][1],dp[i-1][3]+data[i-1].p+data[i].p);
                }
            }
            //j==2;
            if(dp[i-1][1]){
                int times=2*abs(data[i-1].p-data[i].p);
                if(data[i-1].t+times<=data[i].t){
                    dp[i][2]=min(dp[i][2],dp[i-1][1]+abs(data[i-1].p-data[i].p));
                }
            }
            //j==3
            if(dp[i-1][2]){
                int times=3*abs(data[i-1].p-data[i].p);
                if(data[i-1].t+times<=data[i].t){
                    dp[i][3]=min(dp[i][3],dp[i-1][2]+abs(data[i-1].p-data[i].p));
                }
            }
        }
        int mini=min(dp[n][1],dp[n][2]);
        mini=min(mini,dp[n][3]);
        if(mini!=INT) printf("OK %d\n",mini+data[n].p);
        else{
            repin(i,1,n){
                if(dp[i][1]==dp[i][2] && dp[i][2]==dp[i][3] && dp[i][3]==INT){
                    printf("NG %d\n",i);
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 1216