/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-08 13:33:49
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  size_t n = vec.size();
  for (size_t i = 0; i < n; ++i) {
    os << vec[i];
    if (i != n - 1) os << ',';
  }
  os << '}';
  return os;
}
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  os << '{';
  for (auto it = mp.begin(); it != mp.end(); ++it) {
    os << '{' << it->first << ':' << it->second << '}';
    if (it != --mp.end()) os << ',';
  }
  os << '}';
  return os;
}
template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  os << '{';
  for (auto it = st.begin(); it != st.end(); ++it) {
    os << *it;
    if (it != --st.end()) os << ',';
  }
  os << '}';
  return os;
}
template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  size_t n = vec.size();
  for (size_t i = 0; i < n; ++i) is >> vec[i];
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

using ull = unsigned long long;

class RollingHash {
 public:
  RollingHash(const std::string& s) : s_(s) { build(); }

  // get hash value of [l, r)
  std::pair<ull, ull> get(int l, int r) {
    ull ret0 = (hash0_[r] - hash0_[l] * pow0_[r - l] % mod0_ + mod0_) % mod0_;
    ull ret1 = (hash1_[r] - hash1_[l] * pow1_[r - l] % mod1_ + mod1_) % mod1_;
    return {ret0, ret1};
  }

 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> pow0_;
  static std::vector<ull> pow1_;
  static std::mt19937_64 mt_;

  void build() {
    int n = s_.size();
    hash0_.assign(n + 1, 0);
    hash1_.assign(n + 1, 0);
    for (int i = 0; i < n; ++i) {
      hash0_[i + 1] = (hash0_[i] * base0_ + s_[i]) % mod0_;
      hash1_[i + 1] = (hash1_[i] * base1_ + s_[i]) % mod1_;
    }
    for (int i = 0; i < n; ++i) {
      pow0_.emplace_back(pow0_.back() * base0_ % mod0_);
      pow1_.emplace_back(pow1_.back() * base1_ % mod1_);
    }
  }
};

std::mt19937_64 RollingHash::mt_(
    std::chrono::steady_clock::now().time_since_epoch().count());
ull RollingHash::base0_ = std::uniform_int_distribution<ull>(
    2, RollingHash::mod0_ - 1)(RollingHash::mt_);
ull RollingHash::base1_ = std::uniform_int_distribution<ull>(
    2, RollingHash::mod1_ - 1)(RollingHash::mt_);
std::vector<ull> RollingHash::pow0_{1};
std::vector<ull> RollingHash::pow1_{1};

void ABC141_E() {
  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.get(i, i + x) == rh.get(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';
}

void ALDS1_14_B() {
  string t, p;
  cin >> t >> p;
  RollingHash rh0(t);
  RollingHash rh1(p);

  int n = t.size();
  int m = p.size();

  for (int i = 0; i + m <= n; ++i) {
    if (rh0.get(i, i + m) == rh1.get(0, m)) {
      cout << i << '\n';
    }
  }
}

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

  ABC141_E();
  //ALDS1_14_B();

  return 0;
}

Measured memory_bytes: 512