import std.stdio;
import std.algorithm;
import std.functional;
import std.range;
import std.container;
import std.string;
import std.conv;
import std.array;

void main() {
    int n;
test:
    while (n = readln.chomp.to!int, n) {
        int[] a, b;
        void init() {
            auto _ = readln.chomp.split(" ").map!(to!int).array;
            a = _.sort!"a > b".array;
            _ = readln.chomp.split(" ").map!(to!int).array;
            b = _.sort!"a > b".array;
        }
        init();
        int c = 0;
        int index = 0;
        for (int i = 1; i < n; i *= 2) {
            for (int j = 0; j < i; j++) {
                if (a[index] > b[index]) {
                    c++;
                }
                index++;
            }
            if (c > (i * 2 - 1) / 2) {
                (i * 2 - 1).writeln;
                continue test;
            }
        }
        "NA".writeln;
    }
}