import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto s = readln.chomp;

  auto res = 0;

  foreach (k; 0..s.length - 1) {
    foreach (l; k+1..s.length) {
      auto s1 = s[k..l];
      auto s2 = s[l..$];
      auto dp = new int[][](s1.length, s2.length);

      auto lres = 0;
      foreach (i; 0..s1.length) {
        if (s1[i] == s2[0]) {
          dp[i][0] = 1;
          lres = 1;
        }
      }
      foreach (i; 0..s2.length) {
        if (s2[i] == s1[0]) {
          dp[0][i] = 1;
          lres = 1;
        }
      }

      foreach (i; 1..s1.length) {
        foreach (j; 1..s2.length) {
          if (s1[i] == s2[j]) {
            dp[i][j] = dp[i-1][j-1] + 1;
            lres = max(dp[i][j], lres);
          } else {
            dp[i][j] = 0;
          }
        }
      }
      res = max(lres, res);
    }
  }

  res.writeln;
} 
