import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;

    int min_l, max_l = N/2+1;
    while (min_l+1 < max_l) {
        auto l = (min_l + max_l) / 2;
        int[string] memo;
        foreach (i; 0..N-l+1) ++memo[S[i..i+l]];
        bool ok;
        foreach (_, i; memo) if (i > 1) {
            ok = true;
            break;
        }
        if (ok) {
            min_l = l;
        } else {
            max_l = l;
        }
    }
    writeln(min_l);
}