#include <bits/stdc++.h>
const int N = 4e5 + 5;
const int S = 26;
int n, ans(1);
char s[N];
namespace segt {
int lc[N << 5], rc[N << 5], siz[N << 5], total(0);
void insert(int& x, int l, int r, int v) {
  if (!x) x = ++total;
  ++siz[x];
  if (l == r) return;
  if (v <= ((l + r) >> 1))
    insert(lc[x], l, ((l + r) >> 1), v);
  else
    insert(rc[x], ((l + r) >> 1) + 1, r, v);
}
bool find(int x, int l, int r, int ql, int qr) {
  if (!x) return 0;
  if (ql <= l && r <= qr) return siz[x] > 0;
  if (ql > r || l > qr) return 0;
  return find(lc[x], l, ((l + r) >> 1), ql, qr) ||
         find(rc[x], ((l + r) >> 1) + 1, r, ql, qr);
}
int merge(int x, int y) {
  if (!x || !y) return x | y;
  int z = ++total;
  lc[z] = merge(lc[x], lc[y]);
  rc[z] = merge(rc[x], rc[y]);
  return siz[z] = siz[x] + siz[y], z;
}
}  // namespace segt
int ch[N][S], link[N], len[N], epos[N], tpos[N];
int total = 1, last = 1;
void extend(int c) {
  int p = last, np = last = ++total;
  segt::insert(epos[np], 1, n, tpos[np] = len[np] = len[p] + 1);
  for (; p && !ch[p][c]; p = link[p]) ch[p][c] = np;
  if (!p) {
    link[np] = 1;
    return;
  }
  int q = ch[p][c];
  if (len[p] + 1 == len[q]) {
    link[np] = q;
    return;
  }
  int nq = ++total;
  memcpy(ch[nq], ch[q], S << 2), link[nq] = link[q], tpos[nq] = tpos[q];
  len[nq] = len[p] + 1, link[q] = link[np] = nq;
  for (; p && ch[p][c] == q; p = link[p]) ch[p][c] = nq;
}
int buc[N], ord[N], val[N], from[N];
signed main() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; i++) extend(s[i] - 'a');
  for (int i = 1; i <= total; i++) ++buc[len[i]];
  for (int i = 1; i <= total; i++) buc[i] += buc[i - 1];
  for (int i = 1; i <= total; i++) ord[buc[len[i]]--] = i;
  for (int i = total; i > 1; i--) {
    int x = ord[i], f = link[x];
    epos[f] = segt::merge(epos[f], epos[x]);
  }
  for (int i = 2; i <= total; i++) {
    int x = ord[i], f = link[x];
    if (f == 1) {
      val[x] = 1, from[x] = x;
      continue;
    }
    int p = tpos[x];
    if (segt::find(epos[from[f]], 1, n, p - len[x] + len[from[f]], p - 1))
      val[x] = val[f] + 1, from[x] = x;
    else
      val[x] = val[f], from[x] = from[f];
  }
  for (int i = 1; i <= total; i++) ans = (ans < val[i]) ? val[i] : ans;
  printf("%d\n", ans);
  return 0;
}
