#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, dp[N];
long long h[N], p[N];
string s;
unordered_set<long long> q;
inline long long get(int l, int r) { return (h[r] - h[l - 1]) * p[N - r]; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  p[0] = 1;
  for (int i = 1; i < N; i++) {
    p[i] = p[i - 1] * 67;
  }
  cin >> n >> s;
  s = '#' + s;
  for (int i = 1; i <= n; i++) {
    h[i] = h[i - 1] + (s[i] - 'a' + 1) * p[i];
  }
  int ans = 0;
  for (int i = n; i >= 1; i--) {
    dp[i] = dp[i + 1] + 1;
    while (dp[i] > 1 && q.find(get(i, i + dp[i] - 2)) == q.end() &&
           q.find(get(i + 1, i + dp[i] - 1)) == q.end()) {
      dp[i] -= 1;
      for (int j = dp[i + dp[i]]; j > 0; j--) {
        if (q.find(get(i + dp[i], i + dp[i] + j - 1)) != q.end()) {
          break;
        }
        q.insert(get(i + dp[i], i + dp[i] + j - 1));
      }
    }
    ans = max(ans, dp[i]);
  }
  cout << ans;
}
