#include <bits/stdc++.h>
using namespace std;

#define LL long long

const int p1 = 127;
const int p2 = 35534783;

string S;
int N, len;
LL P[500010], H[500010];
bool Hash[p2];

bool check(int m){
	bool flag = false;
	for (int i = m + 1; i + m - 1 <= len; i++){
		LL x;
		x = (P[i - 1] - P[i - m - 1] * H[m] % p2 + p2) % p2;
		Hash[x] = true;
		x = (P[i + m - 1] - P[i - 1] * H[m] % p2 + p2) % p2;
		if (Hash[x]){
			flag = true;
			break;
		}
	}
	for (int i = 1; i + m - 1 <= len; i++){
		int x;
		x = (P[i + m - 1] - P[i - 1] * H[m] % p2 + p2) % p2;
		Hash[x] = 0;
	}
	return flag;
}

int main(){
	cin >> N >> S;
	len = S.length();
	int l = 0, r = len;
	P[0] = 0;
	H[0] = 1;
	for (int i = 1; i <= N; i++){
		P[i] = (P[i - 1] * p1 % p2 + S[i - 1]) % p2;
		H[i] = H[i - 1] * p1 % p2;
	}
	while (l < r){
		int mid = (l + r + 1) >> 1;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	cout << l << endl;
}