#include <bits/stdc++.h>
using namespace std;
const int maxm = ((int)2e5 << 1) + 10, maxn = 2e5 + 10;
int to[maxm], nxt[maxm], head[maxn * 2], e;
int len[maxn * 2], lst, tot, TOT, pre[maxn * 2], ch[maxn * 2][26];
int ls[maxn * 60], rs[maxn * 60], rt[maxn * 2], f[maxn * 2], pos[maxn * 2];
void add(int x, int y) {
  to[++e] = y;
  nxt[e] = head[x];
  head[x] = e;
}
void ins(int x) {
  int np = ++tot, p = lst;
  lst = np;
  len[np] = len[p] + 1;
  while (p && !ch[p][x]) ch[p][x] = np, p = pre[p];
  if (!p)
    pre[np] = 1;
  else {
    int q = ch[p][x];
    if (len[q] == len[p] + 1)
      pre[np] = q;
    else {
      int nq = ++tot;
      len[nq] = len[p] + 1;
      for (int i = 0; i < 26; ++i) ch[nq][i] = ch[q][i];
      pre[nq] = pre[q];
      pre[q] = pre[np] = nq;
      while (ch[p][x] == q && p) ch[p][x] = nq, p = pre[p];
    }
  }
}
int merge(int x, int y) {
  if (!x || !y) return x | y;
  int tmp = ++TOT;
  ls[tmp] = merge(ls[x], ls[y]);
  rs[tmp] = merge(rs[x], rs[y]);
  return tmp;
}
void dfs(int u) {
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    dfs(v);
    rt[u] = merge(rt[u], rt[v]);
    if (!pos[u]) pos[u] = pos[v];
  }
}
void upt(int &o, int l, int r, int x) {
  o = ++TOT;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (x <= mid)
    upt(ls[o], l, mid, x);
  else
    upt(rs[o], mid + 1, r, x);
}
int que(int o, int l, int r, int x, int y) {
  if (x > y) return 0;
  if (!o) return 0;
  if (x <= l && r <= y) return 1;
  int mid = (l + r) >> 1, ret = 0;
  if (x <= mid) ret |= que(ls[o], l, mid, x, y);
  if (y > mid) ret |= que(rs[o], mid + 1, r, x, y);
  return ret;
}
int n;
void dfs1(int u, int now) {
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    int fg = que(rt[now], 1, n, pos[v] - len[v] + len[now], pos[v] - 1);
    if (fg)
      f[v] = f[u] + 1, dfs1(v, v);
    else
      f[v] = f[u], dfs1(v, now);
  }
}
int main() {
  scanf("%d", &n);
  tot = 1;
  lst = 1;
  getchar();
  for (int i = 1; i <= n; ++i) {
    char x;
    scanf("%c", &x);
    ins(x - 'a');
    pos[lst] = i;
    upt(rt[lst], 1, n, i);
  }
  for (int i = 2; i <= tot; ++i) add(pre[i], i);
  dfs(1);
  for (int i = head[1]; i; i = nxt[i]) {
    int v = to[i];
    f[v] = 1;
    dfs1(v, v);
  }
  int ans = 0;
  for (int i = 2; i <= tot; ++i) ans = max(ans, f[i]);
  cout << ans << endl;
  return 0;
}
