#include <bits/stdc++.h>
using namespace std;
int a14;
inline int rd(int l, int r) { return rand() % (r - l + 1) + l; }
const int mxn = 4e5 + 3, mxm = mxn * 20;
int n;
char s[mxn];
int len[mxn], fa[mxn], ts[mxn][26], tt, lst, px[mxn], po[mxn];
inline void ext(int c) {
  int p = lst, np = ++tt, q, nq;
  len[np] = len[p] + 1, lst = np;
  for (; p && !ts[p][c]; p = fa[p]) ts[p][c] = np;
  if (!p)
    fa[np] = 1;
  else {
    q = ts[p][c];
    if (len[q] == len[p] + 1)
      fa[np] = q;
    else {
      nq = ++tt, len[nq] = len[p] + 1, fa[nq] = fa[q],
      memcpy(ts[nq], ts[q], sizeof(ts[q]));
      fa[q] = fa[np] = nq;
      for (; ts[p][c] == q; p = fa[p]) ts[p][c] = nq;
    }
  }
}
inline bool cmp1(int x, int y) { return len[x] < len[y]; }
int rt[mxm], dc;
struct asfd {
  int ls[mxm], rs[mxm];
  inline void ins(int &x, int p, int l = 1, int r = n) {
    x = ++dc;
    if (l == r) return;
    if (p <= ((l + r) >> 1))
      ins(ls[x], p, l, ((l + r) >> 1));
    else
      ins(rs[x], p, ((l + r) >> 1) + 1, r);
  }
  inline bool ask(int x, int lc, int rc, int l = 1, int r = n) {
    if (x == 0) return 0;
    if (lc <= l && r <= rc) return 1;
    if (lc <= ((l + r) >> 1) && ask(ls[x], lc, rc, l, ((l + r) >> 1))) return 1;
    if (rc > ((l + r) >> 1) && ask(rs[x], lc, rc, ((l + r) >> 1) + 1, r))
      return 1;
    return 0;
  }
  inline void mer(int &x, int y, int l = 1, int r = n) {
    if (!y) return;
    if (!x) return x = y, void();
    ++dc, ls[dc] = ls[x], rs[dc] = rs[x], x = dc;
    mer(ls[x], ls[y], l, ((l + r) >> 1)),
        mer(rs[x], rs[y], ((l + r) >> 1) + 1, r);
  }
  inline int num(int x, int l = 1, int r = n) {
    if (!x) return 0;
    if (l == r) return 1;
    return num(ls[x], l, ((l + r) >> 1)) + num(rs[x], ((l + r) >> 1) + 1, r);
  }
} sg;
int dp[mxn];
vector<int> g[mxn];
int da[mxn];
inline void dfs(int x, int d = 0) {
  da[d] = x;
  if (d) {
    int l = 0, r = d - 1, mid, t = po[x];
    while (l < r) {
      mid = (l + r + 1) >> 1;
      int y = da[mid];
      if (sg.ask(rt[y], t - len[x] + len[y], t - 1))
        l = mid;
      else
        r = mid - 1;
    }
    dp[x] = dp[da[l]] + 1;
  }
  for (int i = 0; i < g[x].size(); ++i) dfs(g[x][i], d + 1);
}
int main() {
  tt = lst = 1;
  a14 = scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; ++i) ext(s[i] - 'a'), sg.ins(rt[lst], i), po[lst] = i;
  for (int i = 1; i <= tt; ++i) px[i] = i;
  sort(px + 1, px + tt + 1, cmp1);
  for (int i = tt, x; i > 1; --i)
    x = px[i], sg.mer(rt[fa[x]], rt[x]), po[fa[x]] = po[x];
  for (int i = 2; i <= tt; ++i) g[fa[i]].push_back(i);
  dfs(1);
  int ans = 0;
  for (int i = 2; i <= tt; ++i) ans = max(ans, dp[i]);
  printf("%d\n", ans);
  for (int i = 2; i <= tt; ++i) assert(dp[i] >= dp[fa[i]]);
  return 0;
}
