#pragma region Macros
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define REV(x) reverse(ALL(x))
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define SP << " " <<
#define INF2 1000000000000000037
#define INF  1000000007
#define lwb(x,n) distance(x.begin(),lower_bound(ALL(x),(n)))
#define upb(x,n) distance(x.begin(),upper_bound(ALL(x),(n)))
#define fora(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#ifdef _MY_DEBUG
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define de(...) CHOOSE((__VA_ARGS__,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define de(...)
#endif
using namespace std;
using ll = long long;
using ld = long double;
template<class T = ll> using v = vector<T>;
template<class T = ll> using vv = vector<vector<T>>;
template<class T = ll> using vvv = vector<vector<vector<T>>>;
template<class T> bool maxi(T &a, const T &b){ if(a<b){a=b;return 1;}return 0;}
template<class T> bool mini(T &a, const T &b){ if(b<a){a=b;return 1;}return 0;}
template<class T> ll sumer(const T& a){ return accumulate(ALL(a),0LL); }
template<class T, class U> ostream &operator<<(ostream &os, const pair<T,U> &pe) { os << pe.first << " " << pe.second; return os;}
template<class T> ostream &operator<<(ostream &os, const v<T> &ve) { rep(i,ve.size()) os<< (i?" ":"")<<ve[i]; return os;}
ll topbit(ll a) { return a==0?-1:63-__builtin_clzll(a);}
ll botbit(ll a) { return a==0?64:__builtin_ctzll(a);}
ll popcount(ll a) { return __builtin_popcountll(a);}
#define dame {cout<< retword <<"\n"; return;}
#pragma endregion
//--MODIFS---------------------------------
#pragma region Modifs
#define retword "-1"
#define MOD  1000000007
using P  = pair<ll,ll>;
using TP  = tuple<ll,ll,ll>;
#pragma endregion
//--GLOBAL---------------------------------
int base2=2007;
struct RHash {
    static const int base1 = 1007; 
    static const int mod1 = 1000000007, mod2 = 1000000009;
    int n;
    vector<ll> hash1, hash2, power1, power2;

    RHash(const vector<ll> &s): n((int)s.size()), hash1(n+1,0), hash2(n+1,0), power1(n+1,1), power2(n+1,1) {
        /*if(base2==2){
            mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
            uniform_int_distribution<int> rng(3,1000000005);
            base2=rng(mt);
        }
        */
        rep(i,n){
            hash1[i+1] = (hash1[i] * base1 + s[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + s[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of s[l,r)
    P get(int l, int r) const {
        ll res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        ll res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get hash of s[l,r)+s2[l2,r2)
    P connect(const RHash &s2, int l, int r, int l2, int r2) const {
        if(r == -1) r = n;
        if(r2 == -1) r2 = s2.n;
        P res, h1 = get(l,r), h2 = s2.get(l2,r2);
        res.first=(h1.first+h2.first*power1[r-l])%mod1;
        res.second=(h1.second+h2.second*power2[r-l])%mod2;
        return res;
    }

    // get lcp of s[l,r) and s2[l2,r2)
    ll getLCP(const RHash &s2, int l, int r, int l2, int r2) const {
        if(r == -1) r = n;
        if(r2 == -1) r2 = s2.n;
        int len = min(r-l, r2-l2);
        int low = 0, high = len+1;
        while (high - low > 1) {
            int mid = (low + high)/2;
            if (get(l, l+mid) != s2.get(l2, l2+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};
vector<ll> stove(string &str){
    ll n=str.size();
    vector<ll> res(n);
    rep(i,n) res[i]=str[i]-'a';
    return res;
}
//--MAIN-----------------------------------
void Main() {
    ll N; string S;
    cin>>N>>S;
    RHash rh(stove(S));
    ll ans=0;
    rep(i,N){
        reps(j,i+1,N){
            maxi(ans,rh.getLCP(rh,i,j,j,-1));
        }
    }
    cout<< ans <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // ll Qkai; cin>>Qkai; rep(QQ,Qkai) Main();
    Main();
}
//-----------------------------------------

Measured memory_bytes: 568