#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

template <uint_fast64_t basesize>
class RollingHash {
public:
	using u64 = uint_fast64_t;
	using i32 = int_fast32_t;
	using arr = array<u64, basesize>;
	const u64 mod = (1ull << 61) - 1;
	const u64 m30 = (1ull << 30) - 1;
	const u64 m31 = (1ull << 31) - 1;
	const u64 p31 = (1ull << 31);
	arr base;
	RollingHash() {
		random_device seed_gen;
		mt19937_64 engine(0);
		for (u64 i = 0; i < basesize; ++i) {
			base[i] = (engine() & m30) + m30;
		}
	}
	u64 mul(u64 a, u64 b) {
		u64 au = a >> 31;
		u64 ad = a & m31;
		u64 bu = b >> 31;
		u64 bd = b & m31;
		u64 mid = ad * bu + au * bd;
		u64 midu = mid >> 30;
		u64 midd = mid & m30;
		u64 res = au * bu * 2 + midu + (midd << 31) + ad * bd;
		return res;
	}
	u64 calcMod(u64 v) {
		v = (v & mod) + (v >> 61);
		if (v > mod)v - mod;
		return v;
	}
	vector<arr> calcHash(string &s,i32 l,i32 r) { // s[l,r)のhashを計算
		if (l >= r) {
			vector<arr> res(0);
			return res;
		}
		vector<arr> res(r - l);
		for (i32 j = 0; j < basesize ; ++j) {
			res[0][j] = s[l];
		}
		for (i32 i = 1; i < r - l; ++i) {
			for (i32 j = 0; j < basesize; ++j) {
				res[i][j] = calcMod(mul(res[i - 1][j], base[j]) + s[i + l]);
			}
		}
		return res;
	}
	vector<arr> calcHashLen(string& s, i32 len) {
		i32 l = (i32)s.size() - len + 1;
		vector<arr> pre = calcHash(s, 0, len);
		vector<arr> res(l);
		const u64 pos = mod * 3;
		arr p;
		fill(p.begin(), p.end(), 1);
		if (0 < len) {
			for (i32 j = 0; j < basesize; ++j) {
				res[0][j] = pre[len - 1][j];
			}
		}
		for (i32 i = 0; i < len; ++i) {
			for (i32 j = 0; j < basesize; ++j) {
				p[j] = calcMod(mul(p[j], base[j]));
			}
		}
		for (i32 i = 1; i < l; ++i) {
			for (i32 j = 0; j < basesize; ++j) {
				res[i][j] = calcMod(mul(res[i - 1][j], base[j]) + s[i - 1 + len]);//添え字周りが怪しい
				res[i][j] = calcMod(res[i][j] + pos - mul(s[i - 1], p[j]));				
			}
		}
		return res;
	}
};

constexpr uint_fast64_t  bs = 50;
using arr = array<uint_fast64_t, bs>;
using rh = RollingHash<bs>;

int main() {
	IOS;
	int n;
	string s;
	cin >> n >> s;
	rh r;
	
	int lb = -1, ub = n + 1;
	while (ub - lb > 1) {
		int mid = (ub + lb) / 2;
		multiset<arr> st;
		auto ha = r.calcHashLen(s, mid);
		bool flag = false;
		FOR(i, mid, ha.size()) {
			st.insert(ha[i]);
		}
		REP(i, ha.size()) {
			auto itr = st.find(ha[i]);
			if (itr != st.end()) {
				flag = true;
				break;
			}
			if (i + mid < ha.size()) {
				st.erase(st.find(ha[i + mid]));
			}
			if (i - mid >= 0) {
				st.insert(ha[i - mid]);
			}			
		}
		if (flag) {
			lb = mid;
		} else {
			ub = mid;
		}
	}
	put(lb);
	return 0;
}

Measured memory_bytes: 4460