import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    auto s = readln.chomp;
    
    bool ok(int len) {
        bool ans = false;
        foreach (i; 0 .. n - len) {
            auto f = find(s[i + len .. $], boyerMooreFinder(s[i .. i + len]));
            ans |= f.length > 0;
            
            debug { if (f.length > 0) { writeln(s[i .. i + len]); } }
        }
        
        return ans;
    }
    
    int le = 0, r = n / 2;
    while (le < r) {
        int m = (le + r) / 2 + 1;
        if (ok(m)) { le = m; }
        else { r = m - 1; }
    }
    
    le.writeln;
}