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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

struct RollingHash {
    using ull=unsigned long long;
    static constexpr ull MASK30 = (1ULL << 30) - 1;
    static constexpr ull MASK31 = (1ULL << 31) - 1;
    static constexpr ull MOD = (1ULL << 61) - 1;
    static constexpr ull POSITIVIZER = MOD << 2;
    static std::vector<std::pair<ull, ull>> powBase, powBaseMinus;
    int n;
    std::pair<ull, ull> hash;
    RollingHash() : n(0), hash({0, 0}) {}
    RollingHash(ull src) : n(1), hash({src, src}) {}
    RollingHash(int n, std::pair<ull, ull> hash) : n(n), hash(hash) {}
    static void powBaseCalc(int n) {
        while (powBase.size() <= n) {
            powBase.push_back({calcMod(mul(powBase.back().first, powBase[1].first)),
                               calcMod(mul(powBase.back().second, powBase[1].second))});
            powBaseMinus.push_back({calcMod(mul(powBaseMinus.back().first, powBaseMinus[1].first)),
                                    calcMod(mul(powBaseMinus.back().second, powBaseMinus[1].second))});
        }
    }
    RollingHash &operator+=(const RollingHash &rhs) {
        std::pair<ull, ull> pb = rhs.n > 0 ? powBase[rhs.n] : powBase[-rhs.n];
        n += rhs.n;
        hash = {calcMod(mul(hash.first, pb.first) + rhs.hash.first),
                calcMod(mul(hash.second, pb.second) + rhs.hash.second)};
        return *this;
    }
    template<typename Itr> RollingHash(Itr begin, Itr end) : RollingHash() {
        for (auto itr = begin; itr != end; itr++) { *this += RollingHash(*itr); }
    }
    bool operator==(const RollingHash &rhs) const { return hash == rhs.hash; }
    bool operator!=(const RollingHash &rhs) const { return hash != rhs.hash; }
    RollingHash operator+() const { return *this; }
    RollingHash operator-() const {
        int cn = -n;
        std::pair<ull, ull> pb = cn > 0 ? powBase[cn] : powBase[-cn];
        return RollingHash(cn, {calcMod(POSITIVIZER - mul(hash.first, pb.first)),
                                calcMod(POSITIVIZER - mul(hash.second, pb.second))});
    }
    RollingHash &operator-=(const RollingHash &rhs) { return *this += -rhs; }
    RollingHash operator+(const RollingHash &rhs) const { return RollingHash(*this) += rhs; }
    RollingHash operator-(const RollingHash &rhs) const { return RollingHash(*this) -= rhs; }
    RollingHash diff(const RollingHash &rhs) const {
        int cn = -n + rhs.n;
        std::pair<ull, ull> pb = cn > 0 ? powBase[cn] : powBase[-cn];
        return RollingHash(cn, {calcMod(POSITIVIZER - mul(hash.first, pb.first) + rhs.hash.first),
                                calcMod(POSITIVIZER - mul(hash.second, pb.second) + rhs.hash.second)});
    }
    static ull rng() {
        std::random_device rd;
        return std::uniform_int_distribution<ull>(MOD >> 1, MOD - 1)(rd);
    }
    static ull mul(ull a, ull b) {
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        return (au * bu << 1) + (mid >> 30) + ((mid & MASK30) << 31) + ad * bd;
    }
    static ull calcMod(ull val) {
        val = (val & MOD) + (val >> 61);
        if (val > MOD) { val -= MOD; }
        return val;
    }
    static ull modInv(ull x) {
        ull n = MOD - 2, ret = 1, m = x;
        while (n > 0) {
            if (n & 1) { ret = calcMod(mul(ret, m)); }
            m = calcMod(mul(m, m));
            n >>= 1;
        }
        return ret;
    }
};
std::vector<std::pair<RollingHash::ull, RollingHash::ull>> RollingHash::powBase{{1, 1}, {rng(), rng()}};
std::vector<std::pair<RollingHash::ull, RollingHash::ull>>
    RollingHash::powBaseMinus{{1, 1}, {modInv(powBase[1].first), modInv(powBase[1].second)}};

long long binarySearch(long long ok, long long ng, std::function<bool(long long)> check) {
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}

int N;
string S;
signed main() {
    cin >> N >> S;
    vector<RollingHash> rh(N + 1);
    RollingHash::powBaseCalc(N);
    rep(i, N) { rh[i + 1] = rh[i] + S[i]; }
    cout << binarySearch(0, N, [&](int x) {
        rep(i, N - x + 1) {
            for (int j = i + x; j < N - x + 1; j++) {
                if (rh[i].diff(rh[i + x]) == rh[j].diff(rh[j + x])) { return true; }
            }
        }
        return false;
    }) << endl;
}

Measured memory_bytes: 768