/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << "{";
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i] << ",}"[i == vec.size() - 1];
  }
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << "{" << p.first << " " << p.second << "}";
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;
/*
template<class Z> Z rng(Z a, Z b) {
  static mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<Z>(a, b - 1)(mt);
}
*/
class RollingHash {
 public:
  RollingHash(const std::string& s) : s_(s) { Initialize(); }
  std::pair<ull, ull> GetHash(int left, int right);

 private:
  const std::string s_;
  static ull base0_;
  static ull base1_;
  static constexpr ull mod0_ = 2020202077;
  static constexpr ull mod1_ = 2020202111;
  std::vector<ull> hash0_;
  std::vector<ull> hash1_;
  static std::vector<ull> power0_;
  static std::vector<ull> power1_;
  void Initialize();
  static __gnu_cxx::sfmt19937_64 sfmt_;
};

void RollingHash::Initialize() {
  size_t n = s_.size();
  hash0_.assign(n + 1, 0);
  hash1_.assign(n + 1, 0);
  for (size_t i = 0; i < n; ++i) {
    hash0_[i + 1] = (hash0_[i] * base0_ + s_[i]) % mod0_;
    hash1_[i + 1] = (hash1_[i] * base1_ + s_[i]) % mod1_;
  }
  while (power0_.size() <= n) {
    power0_.emplace_back(power0_.back() * base0_ % mod0_);
    power1_.emplace_back(power1_.back() * base1_ % mod1_);
  }
}

inline std::pair<ull, ull> RollingHash::GetHash(int left, int right) {
  ull ret0 =
      hash0_[right] + mod0_ - hash0_[left] * power0_[right - left] % mod0_;
  if (ret0 >= mod0_) ret0 -= mod0_;
  ull ret1 =
      hash1_[right] + mod1_ - hash1_[left] * power1_[right - left] % mod1_;
  if (ret1 >= mod1_) ret1 -= mod1_;
 
  return {ret0, ret1};
}

__gnu_cxx::sfmt19937_64 RollingHash::sfmt_(chrono::steady_clock::now().time_since_epoch().count());
ull RollingHash::base0_ = uniform_int_distribution<ull>(2, RollingHash::mod0_)(RollingHash::sfmt_);
ull RollingHash::base1_ = uniform_int_distribution<ull>(2, RollingHash::mod1_)(RollingHash::sfmt_);
std::vector<ull> RollingHash::power0_{1};
std::vector<ull> RollingHash::power1_{1};


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

  int n; cin >> n;
  string s; cin >> s;

  RollingHash rh(s);

  auto ok = [&](int x) -> bool{
    for (int i = 0; i + 2 * x <= n; ++i) {
      for (int j = i + x; j + x <= n; ++j) {
        if (rh.GetHash(i, i + x) == rh.GetHash(j, j + x)) {
          return true;
        }
      }
    }
    return false;
  };
 
  int low = 0, high = n / 2 + 1;
 
  while (high - low > 1) {
    int mid = (low + high) >> 1;
    if (ok(mid)) {
      low = mid;
    } else {
      high = mid;
    }
  }

  cout << low << '\n';

  return 0;
}


Measured memory_bytes: 512