#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;

int main()
{
  int N, P[42], T[42];
  while(cin >> N, N) {
    P[0] = 0, T[0] = 0;
    for(int i = 1; i <= N; i++) {
      cin >> P[i] >> T[i];
    }
    P[++N] = 0, T[N++] = INF;

    int dp[2][4] = {{}};
    int *cur = dp[0], *nxt = dp[1];
    bool f = true;

    for(int i = 1; i < N; i++, swap(cur, nxt)) {
      nxt[0] = nxt[1] = nxt[2] = nxt[3] = INF;
      for(int j = 3; j > 0; j--) {
        if(T[i - 1] + (j + 1) * P[i - 1] + P[i] <= T[i])
          nxt[1] = min(nxt[1], cur[j] + P[i - 1] + P[i]);
        if(T[i - 1] + j * abs(P[i - 1] - P[i]) <= T[i])
          nxt[j] = min(nxt[j], cur[j - 1] + abs(P[i - 1] - P[i]));
      }
      if(*min_element(nxt, nxt + 4) == INF) {
        f = false;
        cout << "NG " << i << endl;
        break;
      }
    }
    if(f) {
      cout << "OK " << *min_element(cur, cur + 4) << endl;
    }
  }
}