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

int n;
string s;

bool check(int x) {
    map<string, int> v;
    for(int i = 1; i <= n + 1 - x; i++) {
        string a = s.substr(i - 1, x);
        if(v[a]) {
            if(i - v[a] >= x) return true;
        }
        else v[a] = i;
    }
    return false;
}

int main() {
    cin >> n >> s;
    int l = 0, r = n;
    while(l <= r) {
        int m = (l + r) >> 1;
        if(check(m)) l = m + 1;
        else r = m - 1;
    }
    cout << r << endl;
}
