#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int N;
int dp[5050][5050];
string s;
int main() {
	cin >> N >> s;

	for (int i=N-1; i>=0; i--) {
		for (int j=N-1; j>i; j--) {
			if (s[i] != s[j]) continue;
			dp[i][j] = min({dp[i+1][j+1]+1, j-i, N-j});

		}
	}

	int mx = 0;
	for (int i=0; i<N; i++) {
		for (int j=0; j<N; j++) {
			mx = max(mx, dp[i][j]);
		}
	}

	cout << mx;
}