/**
 *      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 uint64 = 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;

class RollingHash {
 public:
  RollingHash(const std::string& s) : s_(s) { Initialize(); }
  std::pair<unsigned long long, unsigned long long> GetHash(int left, int right);

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

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_;
  }
  power0_.emplace_back(1);
  power1_.emplace_back(1);
  while (power0_.size() <= n) {
    power0_.emplace_back(power0_.back() * base0_ % mod0_);
    power1_.emplace_back(power1_.back() * base1_ % mod1_);
  }
}

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

unsigned long long RollingHash::base0_ = 17;
unsigned long long RollingHash::base1_ = 19;

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