// clang-format off
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>

#include <algorithm>
#include <numeric>
#include <limits>
#include <chrono>
#include <functional>
#include <iterator>
#include <random>
#include <complex>
#include <utility>
#include <type_traits>
#include <tuple>
#include <memory>

#include <vector>
#include <array>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <valarray>

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <csignal>
#include <cstdint>
#include <cstddef>

#ifdef ONLINE_JUDGE
#define NDEBUG
#endif
#include <cassert>
#include <stdexcept>
#include <exception>

// << pair
template <typename T1, typename T2>std::ostream&operator<<(std::ostream&os,const std::pair<T1,T2>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
// << container
template<typename,template<typename...> class...>struct is_instantiation_of:public std::false_type{};
template<template<typename...>class U,template<typename...>class...Us,typename...T>struct is_instantiation_of<U<T...>,U,Us...>:public std::true_type{};
template<typename S,template<typename...>class U,template<typename...>class...Us>struct is_instantiation_of<S,U,Us...>:std::integral_constant<bool,is_instantiation_of<S,Us...>::value>{};

template<typename C>std::ostream&_debug_go(std::ostream&,const C&);
template<typename C,typename=std::enable_if_t<is_instantiation_of<C,std::vector,std::deque,std::set,std::map,std::unordered_set,std::unordered_map,std::multiset,std::multimap,std::unordered_multiset,std::unordered_multimap,std::valarray>::value>>std::ostream&operator<<(std::ostream&os,const C&v){return _debug_go(os,v);}
template<typename T,std::size_t N> std::ostream& operator<<(std::ostream&os,const std::array<T,N>&v){return _debug_go(os,v);}
template<typename C>std::ostream& _debug_go(std::ostream&os,const C& v){bool first=true;os<<"[";for(auto i:v){if(!first)os<<", ";else first=false;os<<i;}return os<<"]";}

struct Debugger{template<typename T>Debugger&operator,(const T&v){std::cerr<<v<<" ";return *this;}} dbg;
#ifndef NDEBUG
#define debug(args...) do {dbg,args; cerr << "\n";} while(0)
#else
#define debug(args...)
#endif

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ITER(i, s, e) for (auto i((s)); i != (e); ++i)
#define IT(i, c) ITER(i, (c).begin(), (c).end())

using namespace std;

using ui = uint32_t;
using ll = int64_t;
using ull = uint64_t;
template <typename T = int> using Pt = complex<T>;

template <typename T>
T cross(const Pt<T>& a, const Pt<T>& b) { return a.real() * b.imag() - a.imag() * b.real(); }

template <typename T>
bool cmpPt(const Pt<T>& a, const Pt<T>& b) {
  return a.real() < b.real() || (a.real() == b.real() && a.imag() < b.imag());
}
// END TEMPLATE
// clang-format on

struct RabinKarp {
  int N;
  string S;
  int M = 1e9 + 7, K = 3;
  const array<int, 3> X{{909435980, 232441943, 149241546}},
      Xinv{{109333169, 589718130, 973179037}};
  vector<array<int, 3>> pw, invPw, H;

  RabinKarp() {}

  RabinKarp(const string& S) : RabinKarp() { init(S); }

  friend istream& operator>>(istream& is, RabinKarp& rk) {
    is >> rk.S;
    rk.init(rk.S);
    return is;
  }

  void init(const string& S) {
    this->S = S;
    N = S.size();
    this->S += '$';

    pw = invPw = vector<array<int, 3>>(N + 2, {1, 1, 1});
    H.resize(N + 2);

    REP(i, N + 1) REP(k, K) {
      pw[i + 1][k] = 1LL * pw[i][k] * X[k] % M;
      invPw[i + 1][k] = 1LL * invPw[i][k] * Xinv[k] % M;
      H[i + 1][k] = (H[i][k] + 1LL * pw[i][k] * S[i]) % M;
    }
  }

  array<int, 3> pow(int k) { return k < 0 ? invPw[-k] : pw[k]; }

  array<int, 3> hash(int i, int k) {
    auto res = H[i + k], tmp = H[i], sh = pow(-i);
    REP(k, K) {
      res[k] -= tmp[k];
      res[k] = 1LL * res[k] * sh[k] % M;
      if (res[k] < 0) res[k] += M;
    }
    return res;
  }

  /*
  int lcp(int i, int j) {
    int lo = 0, hi = N + 1 - max(i, j) + 1;
    while (hi - lo > 1) {
      int m = lo + (hi - lo) / 2;
      if (hash(i, m) == hash(j, m))
        lo = m;
      else
        hi = m;
    }
    return lo;
  }
  */
};

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

  int N;
  cin >> N;
  RabinKarp rk;
  cin >> rk;
  // debug(rk.N, rk.S);

  int lo = 0, hi = N;
  while (hi - lo > 1) {
    int m = lo + (hi - lo) / 2;
    // debug("m:", m);
    set<array<int, 3>> seen;
    bool got = false;
    FOR(i, m, N - m + 1) {
      // debug(i);
      // debug(seen, rk.hash(i, m));
      seen.insert(rk.hash(i - m, m));
      got |= seen.count(rk.hash(i, m));
      if (got) break;
    }
    if (got)
      lo = m;
    else
      hi = m;
  }
  cout << lo << '\n';

  return 0;
}


Measured memory_bytes: 768