def main():
    N = int(input()); INF = float("inf")
    S = str(input())
    #dp[i][j]: S[i,j)でponを挿入した最大回数
    dp = [[0]*(N+1) for _ in range(N+1)]

    for l in range(N): #まず長さを決める
        for i in range(N-l): #0 ~ N-len-1
            j = i + l +1 #0~N
            for k in range(i,j+1,1): #kはi~jの間
                dp[i][j] = max(dp[i][j], dp[i][k] + dp[k][j])
                #本当は二つの遷移は微妙に範囲が違うので分けた方が良いかも。
                if i < k and k < j-1:
                    if S[i] == "p" and S[k] == "o" and S[j-1] == "n":
                        dp[i][j] = max(dp[i][j], dp[i+1][k] + dp[k+1][j-1] + 1)
    #print(dp)
    ans = -1
    for i in range(N):
        if dp[0][i] >= 1 and dp[i][N] >= 1:
            temp = dp[0][i] + dp[i][N] - 2
            ans = max(ans, temp)

    print(ans)

if __name__ == '__main__':
    main()