function main(input) {
    var args = input.trim().split("\n");
    var N = parseInt(args[0]);
    var S = args[1];

    var dp = [];

    for(var i = 0; S.length > i; i++) {
        for(var j = 0; S.length > j; j++) {
            if (typeof dp[i] === "undefined") dp[i] = [];
            if (S[i] === S[j]) {
                var value = i === 0 || j === 0 ? 0 : dp[i - 1][j - 1];
                dp[i].push(value + 1);
            } else {
                dp[i].push(0)
            }
        }
    }

    var result = 0;
    var max = Math.floor(S.length / 2);
    for (var k = 0; S.length > k; k++) {
        for(var l = 0; S.length > l; l++) {
            if (k >= l) continue;
            var now = Math.min(max, dp[k][l])
            result = Math.max(result, now);
        }
    }

    console.log(result);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));