import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ###################################################################### n = ni() s = input() dp = [[0] * (n + 1) for i in range(n+1)] for d in range(3, n+1): for l in range(n-d+1): r = l + d for i in range(l+1, r): dp[l][r] = max(dp[l][r], dp[l][i] + dp[i][r]) if s[l] == "p" and s[r-1] == "n": for i in range(l+1, r): if s[i] == "o": dp[l][r] = max(dp[l][r], dp[l+1][i] + dp[i+1][r] + 1) S = "ponpon" inf = 10 ** 18 dp2 = [[-inf] * 7 for i in range(n+1)] dp2[0][0] = 0 for i in range(n): for j in range(6): if s[i] == S[j]: for l in range(i+1): dp2[i+1][j+1] = max(dp2[i+1][j+1], dp2[l][j] + dp[l][i]) for j in range(7): for l in range(i+1): dp2[i+1][j] = max(dp2[i+1][j], dp2[l][j] + dp[l][i+1]) print(max(-1, dp2[-1][-1]))