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

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

  int m = 0;
  foreach(a; 0..N) {
    for(int b = 1 + a; b < N; b++) {
      int len = 0;
      int i = a, j = b;
      while(i < b && j < N && S[i] == S[j]) {
        i++;
        j++;
        len++;
      }
      m = max(m, len);
    }
  }
  m.writeln;
}
