#include <stdio.h>
int n;
int ans;
char s[5001];
int x[5000];
int y;
int main() {
	scanf("%d", &n);
	scanf(" %s", s);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)x[j] = 0;
		for (int j = i; j < n; j++) {
			if (s[j] == s[j - i])x[j - i]++;
		}
		y = 0;
		for (int j = 0; j < n; j++) {
			if (x[j])y++;
			else y = 0;
			if (y <= i && y > ans)ans = y;
		}
	}
	printf("%d\n", ans);
}