#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 1;
char a[N];
int n, tot, qwq, cnt, last, ans;
int h[N], dp[N], t[N], pos[N];
struct edge {
  int t, n;
} e[N];
int ch[N][26], fa[N], len[N];
int rt[N], ls[N << 5], rs[N << 5];
inline void cpy(int x, int y) {
  for (int i = 0; i <= 25; i++) ch[x][i] = ch[y][i];
}
inline void ins(int x) {
  int p(last), np, q, nq;
  len[np = last = ++tot] = len[p] + 1;
  while (p && !ch[p][x]) ch[p][x] = np, p = fa[p];
  if (!p) return void(fa[np] = 1);
  if (len[q = ch[p][x]] == len[p] + 1) return void(fa[np] = q);
  cpy(nq = ++tot, q), len[nq] = len[p] + 1, fa[nq] = fa[q], fa[q] = fa[np] = nq;
  while (p && ch[p][x] == q) ch[p][x] = nq, p = fa[p];
}
inline void input() { scanf("%d%s", &n, a + 1), last = tot = 1; }
inline void ins(int& p, int L, int R, int x) {
  if (!p) p = ++cnt;
  if (L == R) return;
  int mid = L + R >> 1;
  (x <= mid) ? ins(ls[p], L, mid, x) : ins(rs[p], mid + 1, R, x);
}
inline void add_edge(int x, int y) { e[++qwq] = (edge){y, h[x]}, h[x] = qwq; }
inline void init() {
  for (int i = 1; i <= n; i++)
    ins(a[i] - 'a'), ins(rt[last], 1, n, i), pos[last] = i;
  for (int i = 2; i <= tot; i++) add_edge(fa[i], i);
}
inline int merge(int x, int y) {
  if (!x || !y) return x | y;
  int p = ++cnt;
  ls[p] = merge(ls[x], ls[y]);
  rs[p] = merge(rs[x], rs[y]);
  return p;
}
inline void dfs1(int u) {
  for (int i = h[u], v; v = e[i].t, i; i = e[i].n)
    dfs1(v), rt[u] = merge(rt[u], rt[v]), pos[u] = pos[v];
}
inline int ask(int p, int L, int R, int l, int r) {
  if (!p) return 0;
  if (L == l && R == r) return 1;
  int mid = L + R >> 1;
  if (l > mid) return ask(rs[p], mid + 1, R, l, r);
  if (r <= mid) return ask(ls[p], L, mid, l, r);
  return ask(ls[p], L, mid, l, mid) | ask(rs[p], mid + 1, R, mid + 1, r);
}
inline int find(int x, int y) {
  return ask(rt[y], 1, n, pos[x] - len[x] + len[y], pos[x] - 1);
}
inline void dfs2(int u) {
  if (fa[u] == 1 || find(u, t[fa[u]]))
    dp[u] = dp[fa[u]] + 1, t[u] = u;
  else
    dp[u] = dp[fa[u]], t[u] = t[fa[u]];
  if (ans < dp[u]) ans = dp[u];
  for (int i = h[u], v; v = e[i].t, i; i = e[i].n) dfs2(v);
}
inline void work() { dfs1(1), dfs2(1), cout << ans; }
int main() {
  input();
  init();
  work();
  return 0;
}
