#include <bits/stdc++.h>
using namespace std;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MOD 2305843009213693951

template<u64 mod>
struct RollingHash {
    i64 n;
    vector<u64> hashed, power;

    RollingHash(const string &s, u64 base = 1'000'007) {
        n = s.length();
        hashed.assign(n + 1, 0);
        power.assign(n + 1, 0);
        hashed[0] = 0;
        power[0] = 1;
        REP(i, n) {
            power[i + 1] = calc_mod(mul(power[i], base));
            hashed[i + 1] = calc_mod(mul(hashed[i], base) + s[i]);
        }
    }

    u64 hash(i64 l, i64 r) {
        return calc_mod(hashed[r] + 3 * mod - mul(hashed[l], power[r - l]));
    }

    bool match(i64 l1, i64 r1, i64 l2, i64 r2) {
        return hash(l1, r1) == hash(l2, r2);
    }

private:
    const u64 MASK31 = (1ULL << 31) - 1;
    const u64 MASK30 = (1ULL << 30) - 1;
    const u64 MASK61 = (1ULL << 61) - 1;

    u64 mul(u64 a, u64 b) {
        u64 ah = a >> 31;
        u64 al = a & MASK31;
        u64 bh = b >> 31;
        u64 bl = b & MASK31;
        u64 mid = ah * bl + al * bh;
        u64 midh = mid >> 30;
        u64 midl = mid & MASK30;
        return ah * bh * 2 + midh + (midl << 31) + al * bl;
    }

    u64 calc_mod(u64 x) {
        u64 xh = x >> 61;
        u64 xl = x & MASK61;
        u64 res = xh + xl;
        if (res >= mod) res -= mod;
        return res;
    }
};

int main() {
    i64 N; cin >> N;
    string s; cin >> s;

    RollingHash<MOD> rh(s);

    i64 maxl = 0;
    REP(i, N) {
        for (i64 j = i + 1; j < N; j++) {
            i64 lb = 0;
            i64 ub = j - i + 1;
            while (ub - lb > 1) {
                i64 mid = (lb + ub) / 2;
                if ((i + mid) <= N && (j + mid) <= N && rh.match(i, i + mid, j, j + mid)) lb = mid;
                else ub = mid;
            }
            chmax(maxl, min(lb, j - i));
        }
    }
    cout << maxl << endl;

    return 0;
}

Measured memory_bytes: 512