#include <bits/stdc++.h>
using namespace std;
int n, link[400005], len[400005], ch[400005][26], pos[400005], f[400005],
    g[400005], cnt = 1, last = 1, ans = 1, ls[8000005], rs[8000005], rt[400005],
               tot;
vector<int> G[400005];
char s[200005];
void modify(int &now, int l, int r, int pos) {
  if (!now) now = ++tot;
  if (l == r) return;
  int mid = (l + r) / 2;
  if (pos <= mid)
    modify(ls[now], l, mid, pos);
  else
    modify(rs[now], mid + 1, r, pos);
}
int query(int now, int stdl, int stdr, int l, int r) {
  if (!now) return 0;
  if (l <= stdl && r >= stdr) return 1;
  int mid = (stdl + stdr) / 2, ans = 0;
  if (l <= mid) ans += query(ls[now], stdl, mid, l, r);
  if (r > mid) ans += query(rs[now], mid + 1, stdr, l, r);
  return ans;
}
int merge(int x, int y) {
  if (!x || !y) return x + y;
  int now = ++tot;
  ls[now] = merge(ls[x], ls[y]), rs[now] = merge(rs[x], rs[y]);
  return now;
}
void insert(int x, int id) {
  int p = last, cur = ++cnt;
  last = cur;
  len[cur] = len[p] + 1, modify(rt[cur], 1, n, id), pos[cur] = id;
  while (p && !ch[p][x]) ch[p][x] = cur, p = link[p];
  if (!p) {
    link[cur] = 1;
    return;
  }
  int q = ch[p][x];
  if (len[q] == len[p] + 1) {
    link[cur] = q;
    return;
  }
  int clone = ++cnt;
  memcpy(ch[clone], ch[q], sizeof(ch[clone]));
  len[clone] = len[p] + 1, link[clone] = link[q], link[q] = link[cur] = clone,
  pos[clone] = pos[q];
  while (p && ch[p][x] == q) ch[p][x] = clone, p = link[p];
}
void dfs(int x) {
  for (int to : G[x]) dfs(to), rt[x] = merge(rt[x], rt[to]);
}
void dfs1(int x) {
  for (int to : G[x]) {
    if (link[to] == 1)
      f[to] = 1, g[to] = to;
    else {
      if (query(rt[g[x]], 1, n, pos[to] - len[to] + len[g[x]], pos[to] - 1))
        f[to] = f[x] + 1, g[to] = to;
      else
        f[to] = f[x], g[to] = g[x];
    }
    dfs1(to);
  }
  ans = max(ans, f[x]);
}
int main() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; i++) insert(s[i] - 'a', i);
  for (int i = 2; i <= cnt; i++) G[link[i]].push_back(i);
  dfs(1), dfs1(1);
  printf("%d\n", ans);
  return 0;
}
