#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 4e5 + 5;
char S[MAX_N];
int N;
int ls[MAX_N << 5], rs[MAX_N << 5];
int rt[MAX_N], cnt;
void modify(int &o, int pos, int l = 1, int r = N) {
  if (!o) o = ++cnt;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify(ls[o], pos, l, mid);
  else
    modify(rs[o], pos, mid + 1, r);
}
int merge(int x, int y) {
  if (!x || !y) return x | y;
  if (!ls[x] && !rs[x]) return x;
  int z = ++cnt;
  ls[z] = merge(ls[x], ls[y]);
  rs[z] = merge(rs[x], rs[y]);
  return z;
}
int query(int o, int ql, int qr, int l = 1, int r = N) {
  if (!o) return 0;
  if (ql <= l && r <= qr) return 1;
  int mid = (l + r) >> 1;
  if (ql <= mid && query(ls[o], ql, qr, l, mid)) return 1;
  if (qr > mid && query(rs[o], ql, qr, mid + 1, r)) return 1;
  return 0;
}
int ch[MAX_N][26], fa[MAX_N], len[MAX_N], mrk[MAX_N];
int lst = 1, tot = 1;
void extend(int c, int v) {
  int p = lst, np = ++tot;
  len[np] = len[p] + 1;
  while (p && !ch[p][c]) ch[p][c] = np, p = fa[p];
  if (!p)
    fa[np] = 1;
  else {
    int q = ch[p][c];
    if (len[q] == len[p] + 1)
      fa[np] = q;
    else {
      int nq = ++tot;
      mrk[nq] = mrk[q], fa[nq] = fa[q], fa[q] = fa[np] = nq,
      len[nq] = len[p] + 1;
      for (int i = 0; i < 26; i++) ch[nq][i] = ch[q][i];
      while (p && ch[p][c] == q) ch[p][c] = nq, p = fa[p];
    }
  }
  lst = np, mrk[np] = v, modify(rt[np], v);
}
int buc[MAX_N], Id[MAX_N], Pos[MAX_N], f[MAX_N];
bool check(int x, int y) {
  return query(rt[y], mrk[x] - len[x] + len[y], mrk[x] - 1);
}
int main() {
  scanf("%d %s", &N, S + 1);
  for (int i = 1; i <= N; i++) extend(S[i] - 'a', i);
  for (int i = 1; i <= tot; i++) buc[len[i]]++;
  for (int i = 1; i <= N; i++) buc[i] += buc[i - 1];
  for (int i = 1; i <= tot; i++) Id[buc[len[i]]--] = i;
  for (int i = tot, x; i > 1; i--)
    x = Id[i], rt[fa[x]] = merge(rt[x], rt[fa[x]]);
  for (int i = 2; i <= tot; i++) {
    int x = Id[i];
    if (fa[x] == 1)
      f[x] = 1, Pos[x] = x;
    else {
      if (check(x, Pos[fa[x]]))
        f[x] = f[fa[x]] + 1, Pos[x] = x;
      else
        f[x] = f[fa[x]], Pos[x] = Pos[fa[x]];
    }
  }
  printf("%d\n", *max_element(&f[1], &f[tot + 1]));
  return 0;
}
