#include <bits/stdc++.h>
using namespace std;
const int N = 400010;
int np, cnt, ans, n, tt, tim;
char s[N];
int ch[N][26], fa[N], rt[N], w[N], ls[N * 20], rs[N * 20], f[N], pr[N], l[N],
    head[N], to[N], nxt[N], g[N];
inline int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
inline void insert(int c) {
  int x = np;
  l[np = ++cnt] = l[x] + 1;
  while (x && !ch[x][c]) ch[x][c] = np, x = fa[x];
  int y = ch[x][c];
  if (!y)
    ch[x][c] = np;
  else if (l[y] == l[x] + 1)
    fa[np] = y;
  else {
    int nq = ++cnt;
    l[nq] = l[x] + 1;
    memcpy(ch[nq], ch[y], sizeof(ch[y]));
    fa[nq] = fa[y], fa[y] = fa[np] = nq;
    while (ch[x][c] == y) ch[x][c] = nq, x = fa[x];
  }
}
inline void insert(int l, int r, int p, int &x) {
  x = ++tim;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (p <= mid)
    insert(l, mid, p, ls[x]);
  else
    insert(mid + 1, r, p, rs[x]);
}
inline int merge(int x, int y) {
  if (!x || !y) return x + y;
  int z = ++tim;
  ls[z] = merge(ls[x], ls[y]);
  rs[z] = merge(rs[x], rs[y]);
  return z;
}
inline bool query(int l, int r, int L, int R, int x) {
  if (!x) return 0;
  if (L <= l && r <= R) return 1;
  int mid = (l + r) >> 1;
  if (R <= mid)
    return query(l, mid, L, R, ls[x]);
  else if (L > mid)
    return query(mid + 1, r, L, R, rs[x]);
  else
    return query(l, mid, L, mid, ls[x]) | query(mid + 1, r, mid + 1, R, rs[x]);
}
inline void dfs(int x) {
  g[x] = x;
  for (int i = head[x]; i; i = nxt[i])
    dfs(to[i]), rt[x] = merge(rt[x], rt[to[i]]), g[x] = g[to[i]];
}
inline void solve(int x) {
  ans = max(ans, f[x]);
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (query(1, n, w[g[y]] - l[y] + l[pr[x]], w[g[y]] - 1, rt[pr[x]]))
      pr[y] = y, f[y] = f[x] + 1;
    else
      pr[y] = pr[x], f[y] = f[x];
    solve(y);
  }
}
int main() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; i++)
    insert(s[i] - 'a'), insert(1, n, i, rt[np]), w[np] = i;
  for (int i = 1; i <= cnt; i++)
    to[++tt] = i, nxt[tt] = head[fa[i]], head[fa[i]] = tt;
  dfs(0);
  for (int i = head[0]; i; i = nxt[i])
    f[to[i]] = 1, pr[to[i]] = to[i], solve(to[i]);
  cout << ans;
  return 0;
}
