def max_laugh_sequence(s):
    max_length = 0
    current_length = 0

    for i in range(len(s)):
        if s[i] == 'a':
            # 如果当前字符是 'a',则尝试扩展序列
            if i == 0 or s[i-1] == 'h':  # 如果前一个字符是 'h' 或者这是第一个字符
                current_length += 1
            else:
                current_length = 1
        elif s[i] == 'h':
            # 如果当前字符是 'h',则尝试扩展序列
            if i == 0 or s[i-1] == 'a':  # 如果前一个字符是 'a' 或者这是第一个字符
                current_length += 1
            else:
                current_length = 1
        else:
            # 如果当前字符既不是 'a' 也不是 'h',则重置当前长度
            current_length = 0

        # 更新最大长度
        max_length = max(max_length, current_length)

    return max_length
# 输入处理
n = int(input())
s = input()
# 计算最大笑声长度
result = max_laugh_sequence(s)
print( result)