#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,ans=0;
  string s;
  cin >> n >> s;
  ll dp[n+1][n+1];
  fill(dp[0],dp[n+1],0);
  for(ll i=n-1;i>=0;i--){
    for(ll j=n-1;j>i;j--){
      if(s[i]==s[j]){
        dp[i][j] = max(dp[i][j],dp[i+1][j+1]+1);
        ans = max(ans,min(dp[i][j],j-i));
      }
    }
  }
  cout << ans << endl;
}
