#include <stdio.h>
#define INF ((int)1e9)
int abc(int a) {return ((a<0)?-a:a);}
int min(int a, int b) {return ((a<b)?a:b);}
int main() {
	int dp[45][4],RB[45][2],f[45][4],n,i,j;while (scanf("%d",&n)!=EOF && n) {
		for (i=0;i<4;i++) for (j=0;j<45;f[j][i]=INF,dp[j++][i]=INF);dp[0][0]=0;
		for (i=1;i<=n;scanf("%d %d",&RB[i][0],&RB[i][1]),i++);
		if (RB[1][1]<RB[1][0]) {puts("NG 1");continue;}
		dp[1][1]=RB[1][1];f[1][1]=RB[1][0];
		for (i=2;i<=n;i++) {
			for (j=2;j<4;j++)
				if (RB[i][1]>=dp[i-1][j-1]+abc(RB[i][0]-RB[i-1][0])*j)
					dp[i][j]=RB[i][1],
					f[i][j]=f[i-1][j-1]+abc(RB[i][0]-RB[i-1][0]);
			for (j=1;j<4;j++)
				if (RB[i][1]>=dp[i-1][j]+RB[i-1][0]*(j+1)+RB[i][0])
					if (f[i][1]>f[i-1][j]+RB[i-1][0]+RB[i][0])
						dp[i][1]=RB[i][1],
						f[i][1]=f[i-1][j]+RB[i-1][0]+RB[i][0];
			for (j=1;j<4;j++) if (dp[i][j]==RB[i][1]) break;
			if (j==4) {printf("NG %d\n",i);break;}
		}
		if (i>n) printf("OK %d\n",min(min(f[n][1],f[n][2]),f[n][3])+RB[n][0]);
	}
	return 0;
}