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

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string s) {
    int n = cast(int)s.length;

    // dp[i][j] = i 番目と j 番目から始まる文字列の共通の長さ
    auto dp = new int[][](n, n);

    for (int i = n - 1; i >= 0; i--) {
        for (int j = n - 1; j >= 0; j--) {
            if (s[i] == s[j]) {
                if (i + 1 < n && j + 1 < n)
                    dp[i][j] = dp[i + 1][j + 1] + 1;
                else
                    dp[i][j] = 1;
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans = max(ans, min(j - i, dp[i][j]));
        }
    }
    return ans;
}

void main() {
    readint;
    string s = read!string;
    writeln(calc(s));
}
