import java.util.*; import java.util.regex.Pattern; import java.util.regex.Matcher; class Sample { public static void main(String[] args){ // スキャナーを定義 Scanner scanner = new Scanner(System.in); // 入力値を文字列として取得 String numberAStr = scanner.next(); String numberBStr = scanner.next(); // 正規表現を定義 Pattern pattern = Pattern.compile("^[0-9a-zA-Z]*$"); Matcher matcherA = pattern.matcher(numberAStr); Matcher matcherB = pattern.matcher(numberBStr); // 条件分岐 if(!matcherA.matches()){ System.out.println("NG"); } else if (!matcherB.matches()) { System.out.println("NG"); } else { if(numberAStr.indexOf("0")==1){ System.out.println("NG"); } else if(numberBStr.indexOf("0")==1){ System.out.println("NG"); } else { int numberAInt = Integer.parseInt(numberAStr); int numberBInt = Integer.parseInt(numberBStr); if(numberAInt > 12345){ System.out.println("NG"); } else if (numberBInt > 12345) { System.out.println("NG"); } else { System.out.println("OK"); } } } } }