require 'pp'

n = gets.chomp!.to_i
s = gets.chomp!

chars = {}
ans = {}
s.chars.each_with_index do |ch, i| 
    chars[ch] ||= []
    chars[ch] << i
    if chars[ch].length >= 2
        ans[chars[ch][-2]] = chars[ch][-1]
    end
end

#pp ans
max = 0
start = -1
before_h = -1
before_t = -1
count = 1
ans.sort.to_h.each do |k, v|
    if before_h + 1 == k && before_t + 1 == v && start != k
        if start == -1
            start = before_t
        end
        count += 1
        if count > max
            max = count
        end
    else
        start = -1
        count = 1
    end
    before_h = k
    before_t = v
end

puts max
