#include <iostream>
#include <cstdio>
using namespace std;

int n, mx;
string s;
int main() {
	int i, j, k;
	cin >> n >> s;
	for(i=1; i<n; i++) {
		for(j=k=0; j+i<n; j++) {
			if(s[j] == s[j+i]) k++, mx = max(mx, min(i, k));
			else k = 0;
		}
	}
	cout << mx;
	return 0;
}