n = gets.chomp.to_i
s = gets.chomp
raise 'NO' unless n == s.size
max_len = n / 2

old = {}
new = {}
max = 0
s.each_char.with_index do |c, cindex|
  old_new = new
  _new = {}
  old_new.each do |str, start_index|
    new_str = str + c
    str_size = new_str.size
    next if max_len < str_size

    end_index = old[new_str]
    if end_index
      if (start_index > end_index) && max < str_size
        max = str_size
      end
    else
      old[new_str] = cindex
    end
    _new[new_str] = start_index
  end
  _new[c] = cindex

  new = _new
end

puts max