import java.io.*; import java.util.*; public class Main { static int n; static char[] pons; static int[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); n = sc.nextInt(); pons = sc.next().toCharArray(); dp = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = i + 2; j < n; j++) { dp[i][j] = -1; } } int max = -1; for (int i = 2; i < n - 3; i++) { int left = dfw(0, i); int right = dfw(i + 1, n - 1); if (left > 0 && right > 0) { max = Math.max(max, left + right - 2); } } System.out.println(max); } static int dfw(int start, int end) { if (dp[start][end] < 0) { int max = 0; for (int i = start + 1; i < end; i++) { max = Math.max(max, dfw(start, i) + dfw(i + 1, end)); } if (pons[start] == 'p' && pons[end] == 'n') { for (int i = start + 1; i < end; i++) { if (pons[i] != 'o') { continue; } max = Math.max(max, dfw(start + 1, i - 1) + dfw(i + 1, end - 1) + 1); } } dp[start][end] = max; } return dp[start][end]; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }