#include <bits/stdc++.h>
const int maxn = 2e5 + 7, lo = 0x40000;
const long long hoff = 131, hmod = 1e9 + 7;
int n, la[maxn], sa[maxn], rk[maxn], he[maxn], lg2[lo * 2], st[18][lo * 2];
long long hs[maxn], hop[maxn];
char s[maxn];
inline bool match(int i, int j, int l) {
  --i;
  --j;
  if (std::max(i, j) + l >= n) return false;
  return (hs[i + l] - (i < 0 ? 0 : hs[i] * hop[l] % hmod) + hmod) % hmod ==
         (hs[j + l] - (j < 0 ? 0 : hs[j] * hop[l] % hmod) + hmod) % hmod;
}
inline int lcomm(int i, int j) {
  int l = 0, r = n - std::max(i, j) + 1, mid;
  while (r - l > 1) {
    mid = (l + r) >> 1;
    if (match(i, j, mid))
      l = mid;
    else
      r = mid;
  }
  return l;
}
inline bool cmpSuf(int i, int j) {
  int l = lcomm(i, j);
  return s[i + l] < s[j + l];
}
inline void readin() { scanf("%d%s", &n, s); }
void geneHash() {
  hs[0] = s[0];
  for (int i = 1; i < n; ++i) hs[i] = (hs[i - 1] * hoff + s[i]) % hmod;
  hop[0] = 1;
  for (int i = 1; i < n; ++i) hop[i] = hop[i - 1] * hoff % hmod;
}
void geneSA() {
  for (int i = 0; i < n; ++i) sa[i] = i;
  std::sort(sa, sa + n, cmpSuf);
  for (int i = 0; i < n; ++i) rk[sa[i]] = i;
  for (int i = 1; i < n; ++i) he[i] = lcomm(sa[i - 1], sa[i]);
}
void geneST() {
  for (int i = 1; i < 18; ++i)
    for (int j = 1 << (i - 1); j < (1 << i); ++j) lg2[j] = i - 1;
  for (int i = 0; i < n; ++i) st[0][i] = he[i];
  for (int k = 1; k < 18; ++k)
    for (int i = 0; i + (1 << (k - 1)) < n; ++i)
      st[k][i] = std::min(st[k - 1][i], st[k - 1][i + (1 << (k - 1))]);
}
inline int lcp(int i, int j) {
  if (i == j) return he[i];
  int k = lg2[j - i + 1];
  return std::min(st[k][i], st[k][j - (1 << k) + 1]);
}
inline int divTlcp(int r, int len) {
  if (he[r] < len) return r;
  int l = -1, k = r, mid;
  while (r - l > 1) {
    mid = (l + r) >> 1;
    if (lcp(mid, k) >= len)
      r = mid;
    else
      l = mid;
  }
  return r - 1;
}
inline int divBlcp(int l, int len) {
  int r = n, k = l, mid;
  while (r - l > 1) {
    mid = (l + r) >> 1;
    if (lcp(k + 1, mid) >= len)
      l = mid;
    else
      r = mid;
  }
  return l;
}
int minSeg[lo * 2], temClk;
struct ts {
  int t, v;
} temSeg[lo * 2];
void segBuild() {
  memset(minSeg, 0x7f, sizeof(minSeg));
  temClk = 1;
  memset(temSeg, 0, sizeof(temSeg));
  temSeg[1] = {temClk, -1};
}
void minSegModify(int k, int d) {
  for (k += lo; k > 0; k >>= 1) {
    minSeg[k] = std::min(minSeg[k], d);
  }
}
int minSegQuery(int l, int r) {
  int ans = 0x7f7f7f7f;
  for (l += lo, r += lo; l < r; l >>= 1, r >>= 1) {
    if (l & 1) {
      ans = std::min(minSeg[l], ans);
      ++l;
    }
    if (r & 1) {
      --r;
      ans = std::min(minSeg[r], ans);
    }
  }
  return ans;
}
void temSegModify(int l, int r, int d) {
  ++temClk;
  for (l += lo, r += lo + 1; l < r; l >>= 1, r >>= 1) {
    if (l & 1) {
      temSeg[l] = {temClk, d};
      ++l;
    }
    if (r & 1) {
      --r;
      temSeg[r] = {temClk, d};
    }
  }
}
int temSegQuery(int k) {
  int t = 0, ans = -1;
  for (k += lo; k > 0; k >>= 1) {
    if (temSeg[k].t > t) {
      t = temSeg[k].t;
      ans = temSeg[k].v;
    }
  }
  return ans;
}
int p[maxn], len[maxn], ans[maxn], lab[maxn], lef[maxn], rig[maxn];
int main() {
  readin();
  geneHash();
  geneSA();
  geneST();
  segBuild();
  for (int i = n - 1, j, *k, l, r; i >= 0; --i) {
    j = rk[i];
    p[i] = temSegQuery(j);
    if (p[i] < 0) {
      ans[i] = 1;
      len[i] = 1;
      k = lab + n;
    } else {
      ans[i] = ans[p[i]] + 1;
      len[i] = minSegQuery(lef[p[i]], rig[p[i]]) + len[p[i]] - i;
      k = lab + p[i];
    }
    l = divTlcp(j, len[i]);
    r = divBlcp(j, len[i]);
    lef[i] = *k;
    lab[i] = *k + 1;
    rig[i] = *k + r - l + 1;
    *k = rig[i];
    minSegModify(lef[i], i);
    temSegModify(l, r, i);
  }
  printf("%d\n", *std::max_element(ans, ans + n));
  return 0;
}
