#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto e : s) os << e; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

ll base1, base2, mod1, mod2;
class RollingHash {
  int n;
  vector<ll> hash1, hash2, pow1, pow2;
public:
  RollingHash(const string &S) : n(sz(S)), hash1(n + 1), hash2(n + 1), pow1(n + 1, 1), pow2(n + 1, 1) {
    if (base1 == 0) {
      vector<ll> bases({1009, 1013, 1021, 1031, 1033, 1039});
      vector<ll> mods({1000000007, 1000000009});
      random_device rng;
      base1 = bases[rng() % sz(bases)], base2 = bases[rng() % sz(bases)];
      mod1 = mods[rng() % sz(mods)], mod2 = mods[rng() % sz(mods)];
    }
    rep(i, n) {
      hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
      hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
      pow1[i + 1] = (pow1[i] * base1) % mod1;
      pow2[i + 1] = (pow2[i] * base2) % mod2;
    }
  }
  // S の [l, l + k) のハッシュ値を返す
  inline pll get(int l, int k) const {
    int r = l + k;
    ll res1 = hash1[r] - hash1[l] * pow1[r - l] % mod1;
    if (res1 < 0) res1 += mod1;
    ll res2 = hash2[r] - hash2[l] * pow2[r - l] % mod2;
    if (res2 < 0) res2 += mod2;
    return make_pair(res1, res2);
  }
};

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  RollingHash r(s);
  auto binary_search = [&](int ok, int ng) {
    map<pll, int> mp;
    int cnt = 0;
    auto check = [&](int k) { // i 番目で始まり, 長さ k の文字列で被るものがあるか
      for (int i = 0; i + k <= n; ++i) {
        pll x = r.get(i, k);
        if (mp.count(x) && mp[x] + k <= i) return 1;
        if (!mp.count(x)) mp[x] = i;
      }
      return 0;
    };
    int d = 1;
    while (abs(ng - ok) > d) {
      int mid = (ng + ok) / 2;
      (check(mid) ? ok : ng) = mid;
    }
    return ok;
  };
  cout << binary_search(0, n) << endl;
}


Measured memory_bytes: 6592