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

int main()
{
  int n;
  string s;
  cin >> n >> s;

  vector<vector<int>> t(n + 1, vector<int>(n + 1));

  for (int i = n - 1; i >= 0; i--) {
    for (int j = n - 1; j >= i; j--) {
      if (s[i] == s[j]) {
        t[i][j] = t[i + 1][j + 1] + 1;
      }
    }
  }

  int ans = 0;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (t[i][j] <= j - i) {
        ans = max(ans, t[i][j]);
      }
    }
  }

  cout << ans << endl;
}
