import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

/// Number of k-combinations
T combination(T = long)(T n, T k)
{
    assert(0 <= k);
    assert(0 <= n);
    if (n < k)
        return 0;
    k = min(n - k, k);
    if (k == 0)
        return 1;
    if (k == 1)
        return n;
    return memoize!combination(n - 1, k - 1) + memoize!combination(n - 1, k);
}

void main()
{
    long N = lread();
    long[][] A;
    DList!(Tuple!(long, long)) Q;
    foreach (i; 0 .. N)
    {
        A ~= aryread();
        A[$ - 1][] -= 1;
    }

    // writeln(A);

    foreach (i; 0 .. N)
    {
        Q.insertBack(tuple(i, A[i][0]));
    }
    Q.insertBack(tuple(-1L, -1L));

    auto previousmatch = new long[](N);
    auto iter = new long[](N);
    long cnt;
    long day;
    while (true)
    {
        long a = Q.front[0];
        long b = Q.front[1];
        Q.removeFront();
        if (a == -1 && b == -1)
        {
            if (Q.empty)
                break;
            // foreach (q; Q)
            // {
            //     write(q, " ");
            // }
            Q.insertBack(tuple(-1L, -1L));
            day++;
            // writeln();
            continue;
        }
        if (N - 1 <= iter[a] || N - 1 <= iter[b] || A[a][iter[a]] != b || A[b][iter[b]] != a)
            continue;
        if (day == previousmatch[a] || day == previousmatch[b])
        {
            Q.insertBack(tuple(a, b));
            continue;
        }

        previousmatch[a] = day;
        previousmatch[b] = day;
        cnt++;
        iter[a]++;
        iter[b]++;
        // writefln("%d %d", a, b);
        // writeln(iter);

        if (iter[a] < N - 1)
            Q.insertBack(tuple(b, A[a][iter[a]]));
        if (iter[b] < N - 1)
            Q.insertBack(tuple(a, A[b][iter[b]]));
    }

    writeln(day);

}
