#include <bits/stdc++.h>
using namespace std;
const int M = 600011;
int ed[M], n, m, k, v[M], f[M], c[M][26], len[M], d[M * 20], cnt = 1, las = 1,
                                                             s[M * 20][2], ct;
int rt[M], t[M], a[M];
void ins(int& now, int l, int r, int k) {
  now = ++ct;
  d[now] = 1;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (k <= mid)
    ins(s[now][0], l, mid, k);
  else
    ins(s[now][1], mid + 1, r, k);
}
void SAM(int k) {
  int x = ++cnt, y = las;
  len[x] = len[y] + 1, las = x;
  ins(rt[x], 1, n, len[x]);
  ed[x] = len[x];
  for (; y && !c[y][k]; y = f[y]) c[y][k] = x;
  if (!y) {
    f[x] = 1;
    return;
  }
  int p = c[y][k];
  if (len[p] == len[y] + 1) {
    f[x] = p;
    return;
  }
  int q = ++cnt;
  len[q] = len[y] + 1;
  f[q] = f[p];
  f[p] = f[x] = q;
  memcpy(c[q], c[p], sizeof(c[q]));
  for (; y && c[y][k] == p; y = f[y]) c[y][k] = q;
}
char ch[M];
bool cmp(int a, int b) { return len[a] > len[b]; }
int mrg(int x, int y, int l, int r) {
  if (!y || !x) return x + y;
  int now = ++ct;
  d[now] = d[x] + d[y];
  if (l == r) return now;
  int mid = (l + r) >> 1;
  s[now][0] = mrg(s[x][0], s[y][0], l, mid);
  s[now][1] = mrg(s[x][1], s[y][1], mid + 1, r);
  return now;
}
int ask(int now, int l, int r, int L, int R) {
  if (R < L) return 0;
  if (L <= l && r <= R || !now) return d[now];
  int mid = (l + r) >> 1, k = 0;
  if (L <= mid) k += ask(s[now][0], l, mid, L, R);
  if (R > mid) k += ask(s[now][1], mid + 1, r, L, R);
  return k;
}
int main() {
  scanf("%d\n%s", &n, ch + 1);
  for (int i = 1; i <= n; i++) SAM(ch[i] - 'a');
  for (int i = 1; i <= cnt; i++) a[i] = i;
  sort(a + 1, a + 1 + cnt, cmp);
  for (int i = 1; i <= cnt; i++) {
    int k = a[i];
    v[k] = f[k];
    ed[f[k]] = ed[k];
    rt[f[k]] = mrg(rt[f[k]], rt[k], 1, n);
  }
  for (int i = 1; i < cnt; i++) {
    int x = a[i], y = v[x];
    while (y != 1 && !ask(rt[y], 1, n, ed[x] - (len[x] - len[y]), ed[x] - 1))
      y = f[y];
    t[y] = max(t[y], t[x] + 1);
    t[f[x]] = max(t[f[x]], t[x]);
    if (len[v[f[x]]] > len[y]) v[f[x]] = y;
  }
  printf("%d", t[1]);
}
