print((function (pred, s1, s2) return pred(s1) and pred(s2) and "OK" or "NG" end)(function (s) return (s == "0" or s == s:match("[1-9]%d*")) and tonumber(s) <= 12345 end, io.stdin:read("*l"), io.stdin:read("*l")))