import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.math;
import std.regex;

void main() {
  auto N = readln.chomp.to!int;
  auto S = readln.chomp;

  int answer = 0;
  int[] dpIndex = N.iota.array;
  for (int size = 1; size < N; size++) {
    int[][string] marks;
    string[] next_marks;
    foreach (i; dpIndex) {
      if (i+size > N) continue;

      auto target = S[i..i+size];
      marks[target] ~= i;
      if (marks[target].length == 2) next_marks ~= target;
    }
    
    dpIndex = next_marks.map!(m => marks[m]).joiner.array;
    debug writeln(next_marks);
    debug writeln(dpIndex);

    if (dpIndex.empty) {
      answer = size - 1;
      break;
    }

    if (dpIndex.filter!(i => dpIndex.any!(m => m != i && i-size > m)).empty) {
      answer = size;
      break;
    }
  }

  writeln(answer);
}
