import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional;

int _f(string S, int i, int j) {
  assert(i < j);
  int m = j - i;
  if (j >= S.length || S[i] != S[j]) return 0;
  return min(m, 1 + f(S, i + 1, j + 1));
}

alias f = memoize!_f;

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

  int m = 0;
  foreach(i; 0..N) {
    foreach(j; (1+i)..N) {
      m = max(m, f(S,i,j));
    }
  }
  m.writeln;
}
