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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int off = 1; off < n; ++off) {
    int len = 0;
    for (int i = 0; i < n-off; ++i) { 
      ans = max(ans, len);
      if (len == off) { 
        len = 0;
      }
      else if (s[i] == s[i+off]) ++len;
      else len = 0;
    }
    ans = max(ans, len);
  }
  cout << ans << endl;
}

