#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
inline int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int n, m, sz = 128;
int rk[N], sa[N], wr[N], bk[N], wx[N], he[N];
char cc[N];
inline bool cmp(int a, int b, int j) {
  return wr[a] == wr[b] && wr[a + j] == wr[b + j];
}
inline void gSA() {
  for (int i = 1; i <= n; ++i) ++bk[rk[i] = cc[i]];
  for (int i = 1; i <= sz; ++i) bk[i] += bk[i - 1];
  for (int i = n; i; --i) sa[bk[rk[i]]--] = i;
  int tp, j = 1, p = 0;
  while (p < n) {
    tp = 0;
    for (int i = n - j + 1; i <= n; ++i) wx[++tp] = i;
    for (int i = 1; i <= n; ++i)
      if (sa[i] > j) wx[++tp] = sa[i] - j;
    for (int i = 1; i <= n; ++i) wr[i] = rk[wx[i]];
    for (int i = 0; i <= sz; ++i) bk[i] = 0;
    for (int i = 1; i <= n; ++i) ++bk[wr[i]];
    for (int i = 1; i <= sz; ++i) bk[i] += bk[i - 1];
    for (int i = n; i; --i) sa[bk[wr[i]]--] = wx[i];
    for (int i = 1; i <= n; ++i) wr[i] = rk[i];
    rk[sa[1]] = p = 1;
    for (int i = 2; i <= n; ++i)
      rk[sa[i]] = p += (cmp(sa[i], sa[i - 1], j) ^ 1);
    sz = p, j <<= 1;
  }
  for (int i = 1; i <= n; ++i) {
    he[rk[i]] = he[rk[i - 1]] ? he[rk[i - 1]] - 1 : 0;
    j = sa[rk[i] - 1];
    while (cc[i + he[rk[i]]] == cc[j + he[rk[i]]]) ++he[rk[i]];
  }
}
int mi[N][21], hbt[N];
inline int gmi(int l, int r) {
  ++l;
  if (l > r) return n + 2;
  int k = hbt[r - l + 1];
  return min(mi[l][k], mi[r - (1 << k) + 1][k]);
}
struct node {
  int a, l;
  node() { a = 0, l = 0; }
  node(int na, int nl) { a = na, l = nl; }
  bool operator>(const node &bb) const {
    return a != bb.a ? a > bb.a : l < bb.l;
  }
} s[N << 2];
int p[N << 2];
void bui(int o, int l, int r) {
  p[o] = 1 << 30;
  if (l == r) return;
  int mid = (l + r) >> 1;
  bui((o << 1), l, mid), bui(((o << 1) | 1), mid + 1, r);
}
void modif1(int o, int l, int r, int ll, int rr, node x) {
  if (ll <= l && r <= rr) {
    s[o] = s[o] > x ? s[o] : x;
    return;
  }
  int mid = (l + r) >> 1;
  if (ll <= mid) modif1((o << 1), l, mid, ll, rr, x);
  if (rr > mid) modif1(((o << 1) | 1), mid + 1, r, ll, rr, x);
}
node quer1(int o, int l, int r, int pp) {
  if (l == r) return s[o];
  int mid = (l + r) >> 1;
  node an;
  if (pp <= mid)
    an = quer1((o << 1), l, mid, pp);
  else
    an = quer1(((o << 1) | 1), mid + 1, r, pp);
  return an > s[o] ? an : s[o];
}
void modif2(int o, int l, int r, int pp, int x) {
  if (l == r) {
    p[o] = x;
    return;
  }
  int mid = (l + r) >> 1;
  if (pp <= mid)
    modif2((o << 1), l, mid, pp, x);
  else
    modif2(((o << 1) | 1), mid + 1, r, pp, x);
  p[o] = min(p[(o << 1)], p[((o << 1) | 1)]);
}
int quer2(int o, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) return p[o];
  int mid = (l + r) >> 1, an = 1 << 30;
  if (ll <= mid) an = quer2((o << 1), l, mid, ll, rr);
  if (rr > mid) an = min(an, quer2(((o << 1) | 1), mid + 1, r, ll, rr));
  return an;
}
int ll, rr;
inline void getseq(int x, int k) {
  ll = rr = x;
  int l = 1, r = x;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (gmi(mid, x) >= k)
      ll = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  l = x, r = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (gmi(x, mid) >= k)
      rr = mid, l = mid + 1;
    else
      r = mid - 1;
  }
}
int main() {
  n = rd(), scanf("%s", cc + 1);
  gSA();
  bui(1, 1, n);
  hbt[0] = -1;
  for (int i = 1; i <= n; ++i)
    hbt[i] = hbt[i - 1] + ((i & (-i)) == i), mi[i][0] = he[i];
  for (int j = 1; j <= hbt[n]; ++j)
    for (int i = 1; i <= n - (1 << j) + 1; ++i)
      mi[i][j] = min(mi[i][j - 1], mi[i + (1 << (j - 1))][j - 1]);
  int ans = 0;
  for (int i = n; i; --i) {
    int x = rk[i];
    node nw = quer1(1, 1, n, x);
    int len = 1, an = 1;
    if (nw.l) {
      an = nw.a + 1;
      getseq(x, nw.l);
      len = nw.l + quer2(1, 1, n, ll, rr) - i;
    }
    modif2(1, 1, n, x, i);
    getseq(x, len);
    modif1(1, 1, n, ll, rr, node(an, len));
    ans = max(ans, an);
  }
  printf("%d\n", ans);
  return 0;
}
