#include <bits/stdc++.h>
using namespace std;
const int Seed = 131, M = 10000005;
int n, H[500005];
char s[500005];
bitset<500005> f[2];
bitset<M> vis;
int main() {
  scanf("%d%s", &n, s + 1), reverse(s + 1, s + 1 + n);
  int now = 0;
  for (int i = 1; i <= n; i++) f[now][i] = 1;
  for (int l = 2, sum = 1;; sum += l, l++, now = !now) {
    f[!now].reset(), vis.reset();
    for (int i = sum; i <= n; i++) H[i] = (H[i] * Seed + s[i - l + 2]) % M;
    for (int i = sum; i <= n - l; i++) {
      if (f[now][i]) vis[H[i]] = 1;
      if (vis[H[i + l - 1]] || vis[H[i + l]]) f[!now][i + l] = 1;
    }
    if (f[!now].none()) {
      printf("%d\n", l - 1);
      return 0;
    }
  }
}
