def max(a, b)
  a > b ? a : b
end

def search(i, j)
  (0..($max_length - 3)).each do |n|
    next if $max_counter <= 3 + n
    $max_counter = 3 + n if $string.slice(i + 3, n) == $string.slice(j+ 3, n)
  end
end

N = gets.to_i
$max_length = N / 2
$string = gets.chomp
$max_counter = 0

indexes = {}
(2...$string.length).each do |i|
  moji_3 = [$string[i - 2], $string[i - 1], $string[i]]
  if indexes[moji_3].nil?
    indexes[moji_3] = [i - 2]
  else
    indexes[moji_3] << (i - 2)
  end
end

indexes = indexes.to_a.select { |_k, v| v.length >= 2 }.to_h

indexes.each do |_, index_box|
  index_box.combination(2).each do |i, j|
    search(i, j) if i <= j - 3
  end
end

if $max_counter > 0
  puts $max_counter
  exit
else
  indexes = {}
  (1...$string.length).each do |i|
    moji_2 = [$string[i - 1], $string[i]]
    if indexes[moji_2].nil?
      indexes[moji_2] = [i - 1]
    else
      indexes[moji_2] << (i - 1)
    end
  end
  indexes = indexes.to_a.select { |_k, v| v.length >= 2 }.to_h
  indexes.each do |_, index_box|
    index_box.combination(2).each do |i, j|
      if i + 1 != j && $string.slice(i, 2) == $string.slice(j, 2)
        puts 2
        exit
      end
    end
  end

  if $string.length > 30
    puts 1
    exit
  else
    (0...(N - 1)).each do |i|
      ((i + 1)...(N - 0)).each do |j|
        if $string[i] == $string[j]
          puts 1
          exit
        end
      end
    end
  end
end

puts 0