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

int main() {
  int N,ans=0;
  string S;
  cin >> N >> S;
  vector<vector<int>> V(N+1,vector<int>(N+1,0));
  
  for(int i=N-1;i>=0;i--){
    for(int j=i-1;j>=0;j--){
      if(S[i]==S[j]){
        V[i][j] = min((i-j),(V[i+1][j+1]+1));
        ans = max(ans,V[i][j]);
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}
