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

alias f = memoize!_f;

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

  auto dp = new int[][N];
  foreach(ref d; dp) {
    d = new int[N];
  }

  for(int i = N - 2; i >= 0; i--) {
    for(int j = N - 1; j > i; j--) {
      if(S[i] != S[j]) {
        dp[i][j] = 0;
      } else if(j == N - 1) {
        dp[i][j] = 1;
      } else {
        dp[i][j] = 1 + dp[i+1][j+1];
      }
    }
  }

  int m = 0;
  foreach(i; 0..N) {
    foreach(j; (1+i)..N) {
      m = max(m, min(j-i, dp[i][j]));
    }
  }
  m.writeln;
}
