// Arup Guha
// 4/15/2017
// Solution to 2017 NAIPC Problem A: Pieces of Parentheses

import java.util.*;

public class pieces {

	public static void main(String[] args)  {

		// Read in input.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		item[] list = new item[n];
		for (int i=0; i<n; i++)
			list[i] = new item(stdin.next());
		Arrays.sort(list);

		// Run DP here.

		// dp i stores max length for each "count"
		// dp[i] is really for count
		int[] dp = new int[90001];
		Arrays.fill(dp, -1);
		dp[0] = 0;
		int[] highest = new int[90001];
		Arrays.fill(highest, -1);
		highest[0] = 0;

		// Consider adding each item.
		for (int i=0; i<n; i++) {

			if (list[i].diff >= 0) {

				// j = # of opens more than closes.
				for (int j=dp.length-1; j>=list[i].diff; j--) {

					// list[i] has open, close, low, total
					int prev = j-list[i].diff;

					if (dp[prev] == -1) continue;
					if (highest[prev]+list[i].low<0) continue;

					if (dp[prev] + list[i].total > dp[j]) {
						dp[j] = dp[prev] + list[i].total;
						highest[j] = highest[prev] + list[i].diff;
					}
					else if (dp[prev] + list[i].total == dp[j] && highest[prev] + list[i].diff > highest[j]) {
						highest[j] = highest[prev] + list[i].diff;
					}
				}

			}

			else {

				// j = # of opens more than closes.
				for (int j=0; j-list[i].diff<dp.length; j++) {

					// list[i] has open, close, low, total
					int prev = j-list[i].diff;

					if (dp[prev] == -1) continue;
					if (highest[prev]+list[i].low<0) continue;

					if (dp[prev] + list[i].total > dp[j]) {
						dp[j] = dp[prev] + list[i].total;
						highest[j] = highest[prev];
					}
					else if (dp[prev] + list[i].total == dp[j] && highest[prev] > highest[j]) {
						highest[j] = highest[prev];
					}
				}
			}
		}

		// Here is the result.
		System.out.println(dp[0]);
	}
}

class item implements Comparable<item> {

	public int open;
	public int close;
	public int low;
	public int total;
	public int diff;

	public item(String s) {

		// all start at 0
		low = 0;
		open = 0;
		close = 0;
		total = s.length();

		// update reading in string.
		for (int i=0; i<s.length(); i++) {
			if (s.charAt(i) =='(') {
				open++;
			}
			else {
				close++;
				low = Math.min(low, open-close);
			}
		}

		diff = open-close;
	}

	// This is the key to the problem, first, sort by low, then difference! This puts all that never fall negative first, but then of those
	// prioritizes those loaded with opens.
	public int compareTo(item other) {
		if (this.low != other.low)
			return other.low - this.low;
		if (this.diff != other.diff)
			return other.diff - this.diff;
		return this.total - other.total;
	}

	public String toString() {
		return total+":"+low+":"+diff;
	}
}