#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}

struct RndGen{
private:
    std::random_device seed_gen;
    std::mt19937 engine;
    uniform_int_distribution<> uni_dist;
public:
    RndGen(int lb, int ub){
        this->engine = std::mt19937(this->seed_gen());
        this->uni_dist = uniform_int_distribution<>(lb, ub);
    }
    
    int getUniIntRnd(){
        return this->uni_dist(this->engine);
    }
};

template< unsigned mod >
struct RollingHash {
    vector< unsigned > hashed, power;
    
    inline unsigned mul(unsigned a, unsigned b) const {
        unsigned long long x = (unsigned long long) a * b;
        unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
        asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod));
        return m;
    }
    
    RollingHash(const string &s, unsigned base = 10007) {
        int sz = (int) s.size();
        hashed.assign(sz + 1, 0);
        power.assign(sz + 1, 0);
        power[0] = 1;
        for(int i = 0; i < sz; i++) {
            power[i + 1] = mul(power[i], base);
            hashed[i + 1] = mul(hashed[i], base) + s[i];
            if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
        }
    }
    
    unsigned get(int l, int r) const {
        unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
        if(ret >= mod) ret -= mod;
        return ret;
    }
    
    unsigned connect(unsigned h1, int h2, int h2len) const {
        unsigned ret = mul(h1, power[h2len]) + h2;
        if(ret >= mod) ret -= mod;
        return ret;
    }
    
    int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) {
        int len = min(r1 - l1, r2 - l2);
        int low = -1, high = len + 1;
        while(high - low > 1) {
            int mid = (low + high) / 2;
            if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
            else high = mid;
        }
        return (low);
    }
};

const unsigned int mod1 = 1000000007;
const unsigned int mod2 = 1000000009;
const unsigned int mod3 = 998244353;

using RH1 = RollingHash< mod1 >;
using RH2 = RollingHash< mod2 >;
using RH3 = RollingHash< mod3 >;

const unsigned int base1 = 1000037;
const unsigned int base2 = 1000033;

struct RollingHashMultiple{
private:
    RH1 rh1;
    RH2 rh2;
    RH3 rh3;
    
public:
    RollingHashMultiple(string& s)
    : rh1(s, base1),
    rh2(s, base2),
    rh3(s, std::make_unique<RndGen>(mod3/2, mod3-2)->getUniIntRnd()){}
    
    bool match(int l1, int r1, int l2, int r2){
//        if(rh1.get(l1, r1) != rh1.get(l2, r2)) return false;
        if(rh2.get(l1, r1) != rh2.get(l2, r2)) return false;
        if(rh3.get(l1, r1) != rh3.get(l2, r2)) return false;
        return true;
    }
};


ll N;
string S;


bool can(ll K, RollingHashMultiple& rhm){
    rep(l, N-K+1){
        FOR(ls, l+K, N-K+1){
            if(rhm.match(l, l+K, ls, ls+K)) return true;
        }
    }
    return false;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N; cin >> S;
    auto rhm = RollingHashMultiple(S);
    ll ok = 0, ng = N;
    while(abs(ok - ng) > 1){
        ll mid = (ok+ng)/2;
        if(can(mid, rhm)) ok = mid;
        else ng = mid;
    }
    cout << ok << endstr;
    
    return 0;
}


Measured memory_bytes: 508