#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct SuffixArray{
    vector<int> suffix_array;
    const string s;
    const int n;

    SuffixArray(const string& str) : s(str), n((int)str.size()) {
        suffix_array.resize(n + 1);
        vector<int> rank(n + 1), nxt_rank(n + 1);
        for(int i = 0; i <= n; ++i){
            suffix_array[i] = i;
            rank[i] = i < n ? s[i] : -1;
        }

        for(int k = 1; k <= n; k <<= 1){
            auto comp = [&](int i, int j) -> bool {
                if(rank[i] != rank[j])  return rank[i] < rank[j];
                else{
                    int ni = i + k <= n ? rank[i + k] : -1;
                    int nj = j + k <= n ? rank[j + k] : -1;
                    return ni < nj;
                }
            };
            sort(begin(suffix_array), end(suffix_array), comp);
            
            nxt_rank[suffix_array[0]] = 0;
            for(int i = 1; i <= n; ++i){
                nxt_rank[suffix_array[i]] = nxt_rank[suffix_array[i - 1]]
                                            + comp(suffix_array[i - 1], suffix_array[i]);
            }
            copy(begin(nxt_rank), end(nxt_rank), begin(rank));
        }
    }

    int operator[](int k) const { return suffix_array[k]; }

    int size() const { return n; }

    // s 中に t があるか O(|t|*log|s|)
    bool is_contain(const string& t){
        int lb = 0, ub = n;
        while(ub - lb > 1){
            int mid = (lb + ub) / 2;
            if(s.compare(suffix_array[mid], t.length(), t) < 0) lb = mid;
            else    ub = mid;
        }
        return s.compare(suffix_array[ub], t.length(), t) == 0;
    }

    void output() {
        for(int i = 0; i <= n; ++i){
            cout << i << "(" << suffix_array[i] << "):" << s.substr(suffix_array[i]) << '\n';
        }
    }
};

template<typename T>
struct SparseTable{
    vector<vector<T>> table;
    vector<int> power_index;

    SparseTable() = default;
    
    SparseTable(vector<T>& data){
        int n = data.size();
        int bound = 1;
        while((1 << bound) <= n)    ++bound;
        table.resize(bound, vector<T>(n));
        for(int i = 0; i < n; ++i)  table[0][i] = data[i];
        for(int i = 1; i < bound; ++i){
            for(int j = 0; j + (1 << i) <= n; ++j){
                table[i][j] = min(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]);
            }
        }
        power_index.resize(n + 1);
        power_index[0] = power_index[1] = 0;
        for(int i = 2; i <= n; ++i) power_index[i] = power_index[i >> 1] + 1;
    }
    
    // [l, r)
    inline T query(int l, int r){
        int p = power_index[r - l];
        return min(table[p][l], table[p][r - (1 << p)]);
    }
};

// 最長共通接頭辞配列
struct LongestCommonPrefixArray{
    const SuffixArray& SA;
    vector<int> LCP, rank;
    SparseTable<int> table;
    const int n;

    LongestCommonPrefixArray(const SuffixArray& SA) : SA(SA), n(SA.size()) {
        LCP.resize(n + 1);
        rank.resize(n + 1);
        for(int i = 0; i <= n; ++i) rank[SA[i]] = i;
        
        int h = 0;
        LCP[0] = 0;
        for(int i = 0; i < n; ++i){
            // 文字列中での位置 i の接尾辞と、接尾辞配列中でその一つ前の接尾辞の LCP を求める
            int j = SA[rank[i] - 1];

            // 先頭の分をデクリメント
            if(h > 0)   --h;
            for(; j + h < n && i + h < n; ++h){
                if(SA.s[j + h] != SA.s[i + h])  break;
            }
            LCP[rank[i] - 1] = h;
        }

        table = SparseTable(LCP);        
    }

    int get_LCP(int i, int j) {
        if(rank[i] > rank[j])   swap(i, j);
        return table.query(rank[i], rank[j]);
    }

    int operator[](int k) const { return LCP[k]; }

    size_t size() const { return LCP.size(); }

    void output() {
        for(int i = 0; i < size(); ++i){
            cout << i << ':' << LCP[i] << ',' << SA.s.substr(SA[i]) << '\n';
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    string s;
    cin >> n >> s;
    SuffixArray table(s);
    LongestCommonPrefixArray LCP(table);

    int ans = 0;
    for(int i = 0; i + 1 < n; ++i){
        for(int j = i + 1; j < n; ++j){
            chmax(ans, min(LCP.get_LCP(i, j), j - i));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3892