#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

template< typename T >
struct SparseTable {
  vector< vector< T > > st;
  vector< int > lookup;

  SparseTable(const vector< T > &v = vector< T >(3)) {
    int b = 0;
    while((1 << b) <= v.size()) ++b;
    st.assign(b, vector< T >(1 << b));
    for(int i = 0; i < v.size(); i++) {
      st[0][i] = v[i];
    }
    for(int i = 1; i < b; i++) {
      for(int j = 0; j + (1 << i) <= (1 << b); j++) {
        st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
      }
    }
    lookup.resize(v.size() + 1);
    for(int i = 2; i < lookup.size(); i++) {
      lookup[i] = lookup[i >> 1] + 1;
    }
  }

  inline T rmq(int l, int r) {
    int b = lookup[r - l];
    return min(st[b][l], st[b][r - (1 << b)]);
  }
};

//蟻本写経版 O(N*(logN)^2)
struct SuffixArray{
    VI sa,lcp;
    int k;
    const string S;
    VI rank,tmp,lcrank;
    int n;
    SparseTable<int> st;

    SuffixArray(const string &str) : S(str){
        sa.resize(S.size()+1);
        rank.resize(S.size()+1);
        tmp.resize(S.size()+1);
        n = S.size();
        construct_sa();
        construct_lcp();
    }

    // (rank[i],rank[i+k]),(rank[j],rank[j+k])を比較
    bool compare_sa(int i, int j){
        if(rank[i] != rank[j]) return rank[i] < rank[j];

        int ri = i + k <= n ? rank[i+k] : -1;
        int rj = j + k <= n ? rank[j+k] : -1;
        return ri < rj;
    }

    void construct_sa(){
        int n = S.length();
        for(int i = 0; i <= n; i++){
            sa[i] = i;
            rank[i] = i < n ? S[i] : -1;
        }

        for(k = 1; k <= n; k *= 2){
            sort(sa.begin(),sa.end(),[this](int a, int b){
                return compare_sa(a,b);
            });

            tmp[sa[0]] = 0;
            for(int i = 1; i <= n; i++){
                tmp[sa[i]] = tmp[sa[i-1]] + (compare_sa(sa[i-1],sa[i]) ? 1 : 0);
            }
            for(int i = 0; i <= n; i++){
                rank[i] = tmp[i];
            }
        }
    }

    bool contain(string T){
        int l = 0, r = n;
        while(r-l > 1){
            int mid = (r+l) / 2;
            if(S.compare(sa[mid], T.length(), T) < 0) l = mid;
            else r = mid;
        }
        return S.compare(sa[r], T.length(), T) == 0;
    }

    void construct_lcp(){
        lcrank.resize(n+1);
        lcp.resize(n);
        for(int i = 0; i <= n; i++) lcrank[sa[i]] = i;

        int h = 0;
        lcp[0] = 0;
        for(int i = 0; i < n; i++){
            int j = sa[lcrank[i]-1];

            if(h > 0) h--;
            for(; j+h < n && i+h < n; h++){
                if(S[j+h] != S[i+h]) break;
            }
            lcp[lcrank[i]-1] = h;
        }

        st = SparseTable<int>(lcp);

    }

    // lcp of str.substr(a) & str.substr(b)
    int getLCP(int a, int b){
        return st.rmq(min(lcrank[a],lcrank[b]),(max(lcrank[a],lcrank[b])));
    }
};



signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;

    SuffixArray SA(S);
    int res = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            int lcp = SA.getLCP(i,j);
            lcp = min(lcp, j-i);
            res = max(res,lcp);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 896