function Main(input) {
	input = input.split('\n');
	var n = input[0];
	var s = input[1];

	var tmp, reg, len, results = [];
	for (var i = 0; i < n; i++) {
		for (var j = 1; j < n - i; j++) {
			tmp = s.substr(i, j);
			reg = new RegExp(tmp, 'g');
			len = s.match(reg).length;

			if (len < 2) {
				break;
			}
			results.push(tmp.length);
		}
	}

	if (results.length > 0) {
		console.log(Math.max.apply(null, results));
	} else {
		console.log(0);
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));