// Arup Guha
// 5/29/2023
// Solution to 2023 NAC Problem K: Space Alignment

import java.util.*;

public class k {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		
		// Set up variables.
		int open = 0;
		ArrayList<Integer>[] s;
		ArrayList<Integer>[] t;
		s = new ArrayList[51];
		t = new ArrayList[51];
		for (int i=0; i<51; i++) s[i] = new ArrayList<Integer>();
		for (int i=0; i<51; i++) t[i] = new ArrayList<Integer>();
		boolean hass = false;
		boolean hast = false;
		
		// Loop through lines.
		for (int i=0; i<n; i++) {
		
			char[] line = stdin.next().toCharArray();
			
			// Count spaces and tabs.
			int mys = 0, myt = 0;
			for (int j=0; j<line.length-1; j++) {
				if (line[j] == 's') mys++;
				else myt++;
			}
			
			// Update counters and open count.
			if (mys > 0) hass = true;
			if (myt > 0) hast = true;
			
			// Updating open count for close.
			if (line[line.length-1] == '}') open--;
			
			// For this level of openness we add how many spaces and tabs.
			s[open].add(mys);
			t[open].add(myt);
			
			// For open.
			if (line[line.length-1] == '{') open++;
		}
		
		int res = -1;
		
		// tV is what we're trying for the tab.
		for (int tV=1; tV<=1000; tV++) {
			
			
			int numOne = -1;
			boolean possible = true;
			
			// Go through each possible level of nesting.
			for (int i=0; i<=50; i++) {
				
				// Nothing was nested at this level.
				if (s[i].size() == 0) continue;
				
				// Look at everything nested at this level.
				for (int j=0; j<s[i].size(); j++) {
					
					// Number of spaces for this line.
					int cnt = s[i].get(j) + tV*t[i].get(j);
					
					// This isn't possible.
					if (cnt != 0 && i == 0) possible = false;
					
					// Assign what one level of spacing is.
					else if (numOne == -1) {
						if (i == 1) numOne = cnt;
					}
					
					// See if this one is inconsistent.
					else {
						if (cnt != i*numOne) possible = false;
					}
					
					// Get out.
					if (!possible) break;
				}
				
				// Get out.
				if (!possible) break;
			}
			
			// If we get here and it's still possible, this is the answer.
			if (possible) {
				res = tV;
				break;
			}
		}
		
		// Ta da!
		System.out.println(res);
	}
}