#include<iostream>
#include<string.h>
#include<vector>
using namespace std;

int a,b,to=0;
int t[102][102];

bool dfs(int i){
    if(i==2){
        if(!to)return 1;
    }
    for(int j=0;j<100;j++){
        if(t[i][j]){
            t[i][j]--;
            to--;
            if(dfs(j))return 1;
            t[i][j]++;
            to++;
        }
        else if(t[j][i]){
            t[j][i]--;
            to--;
            if(dfs(j))return 1;
            t[j][i]++;
            to++;
        }
    }
    return 0;
}
int main(){
    memset(t,0,sizeof(t));
    while(cin>>a>>b){
        if(a!=0){
            t[a][b]++;
            to++;
        }
        else{
            if(dfs(1))cout<<"OK"<<endl;
            else cout<<"NG"<<endl;
            memset(t,0,sizeof(t));
            to=0;
        }
    }
}