#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int n, f[maxn], ans;
char s[maxn];
unsigned long long base[maxn], hashh[maxn];
set<unsigned long long> S;
unsigned long long gethash(int l, int r) {
  return hashh[r] - hashh[l - 1] * base[r - l + 1];
}
bool check(int pos, int len) {
  unsigned long long temp = gethash(pos - len + 2, pos);
  if (S.find(temp) != S.end()) return true;
  temp = gethash(pos - len + 1, pos - 1);
  if (S.find(temp) != S.end()) return true;
  return false;
}
void insert(int pos) {
  for (int i = f[pos]; i; i--) {
    unsigned long long temp = gethash(pos - i + 1, pos);
    if (S.find(temp) != S.end()) return;
    S.insert(temp);
  }
}
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  reverse(s + 1, s + 1 + n);
  base[0] = 1;
  for (int i = 1; i <= n; i++) base[i] = base[i - 1] * 13331;
  for (int i = 1; i <= n; i++) hashh[i] = hashh[i - 1] * 13331 + s[i] - 'a' + 1;
  S.insert(0);
  for (int i = 1; i <= n; i++) {
    f[i] = f[i - 1] + 1;
    while (f[i] && !check(i, f[i])) insert(i - (--f[i]));
    ans = max(ans, f[i]);
  }
  printf("%d\n", ans);
  return 0;
}
