#include <bits/stdc++.h>
using namespace std;
int n;
const int mod = 7e6 + 7;
bool CT[2][1 << 19];
bitset<mod> se;
int f[1 << 19];
char ss[1 << 19];
int main() {
  scanf("%d", &n);
  scanf("%s", &ss[1]);
  int ans = 1;
  for (int i = 1; i <= n; i++) CT[1][i] = 1, f[i] = ss[i];
  for (int le = 2; le <= 1000; le++) {
    se = 0;
    fill(CT[le & 1] + 1, CT[le & 1] + n + 1, 0);
    for (int j = n - le; j >= 1; j--) {
      if (CT[(le & 1) ^ 1][j + le]) se[f[j + le]] = 1;
      if (se[f[j]] || se[f[j + 1]]) CT[le & 1][j] = 1, ans = le;
    }
    for (int j = 1; j <= n - le + 1; j++)
      f[j] = (f[j] * 233 + ss[j + le - 1]) % mod;
  }
  printf("%d", ans);
}
