import java.util.*;
public class flipping_evan
{
	public static int k;
	
	public static void main(String[] args) throws Exception
	{
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		
		String[] ps = new String[n - 1];
		String[] rs = new String[n - 1];
		for(int x = 0; x < n - 1; x++)
		{
			ps[x] = in.next();
			rs[x] = reverse(ps[x]);
		}
		
		String seq = in.next();
		String rev = reverse(seq);
		k = seq.length();
		
		int[] s = new int[k];
		for(int y = 0; y < seq.length(); y++)
		{
			s[y] = type(seq.charAt(y));
		}
		
		AhoCorasick ac = new AhoCorasick(ps);
		ac.createTrie();
		ac.createDFA();
		
		AhoCorasick rt = new AhoCorasick(rs);
		rt.createTrie();
		
		if(seq.charAt(0) == 'H')
		{
			System.out.println(0);
			return;
		}
		
		int[] matches = new int[k];
		boolean[] need = new boolean[k];
		int start = -1;
		
		int state = 0;
		for(int y = 0; y < s.length - 1; y++)
		{
			state = ac.transition[s[y]][state];
			matches[y + 1] = (matches[y] + ac.count[state]) % 2;
			if((matches[y + 1] == s[y + 1]) ^ (matches[y] == s[y]))
			{
				need[y] = true;
				start = y;
			}
		}
		
		if(start == -1)
		{
			System.out.println(-1);
			return;
		}
		
		String str = rev.substring(revIndex(start)) + '#' + rev;
		int[] zs = zValues(str);
		
		int minLength = 1;
		int maxLength = k + 1;
		for(int z = 1; z < rev.length(); z++)
		{
			if(!need[revIndex(z)])
			{
				minLength = Math.max(minLength, zs[zs.length - k + z] + 1);
			}
			else
			{
				maxLength = Math.min(maxLength, zs[zs.length - k + z]);
			}
		}
		
		if(minLength > maxLength)
		{
			System.out.println(0);
			return;
		}
		
		int result = maxLength - minLength + 1;
		int node = 0;
		for(int z = 0; z < maxLength; z++)
		{
			int index = start - z;
			node = rt.children[s[index]][node];
			if(node == 0)
			{
				break;
			}
			
			if(z+1 >= minLength && rt.leaf[node] == 1)
			{
				result--;
			}
		}
		
		System.out.println(result);
	}
	
	public static int type(char ch)
	{
		return ch == 'T' ? 0 : 1;
	}
	
	public static int revIndex(int index)
	{
		return k - index - 1;
	}
	
	public static String reverse(String str)
	{
		return new StringBuilder(str).reverse().toString();
	}
	
	public static int[] zValues(String s)
	{
		int[] zv = new int[s.length()];
		zv[0] = s.length();
		
		int l = 0;
		int r = 0;
		for(int i = 1; i < s.length(); i++)
		{
			if(i > r)
			{
				l = i;
				r = i;
				
				while(r < s.length() && s.charAt(r - l) == s.charAt(r))
				{
					r++;
				}
				
				r--;
				zv[i] = r - l + 1;
			}
			else
			{
				int k = i - l;
				
				if(zv[k] < r - i + 1)
				{
					zv[i] = zv[k];
				}
				else
				{
					l = i;
					
					while(r < s.length() && s.charAt(r - l) == s.charAt(r))
					{
						r++;
					}
					
					r--;
					zv[i] = r - l + 1;
				}
			}
		}
		
		return zv;
	}
	
	static class AhoCorasick
	{
		public static int ALPHA = 2;
		
		String[] strs;
		int[][] children;
		int[] leaf;
		int nodeCount;
		int[][] transition;
		int[] count;
		
		public AhoCorasick(String[] s)
		{
			strs = s;
		}
		
		public void createTrie()
		{
			int maxNodes = 1;
			for(String s : strs)
			{
				maxNodes += s.length();
			}
			
			children = new int[ALPHA][maxNodes];
			leaf = new int[maxNodes];
			nodeCount = 1;
			for(String s : strs)
			{
				int node = 0;
				for(char ch : s.toCharArray())
				{
					int c = type(ch);
					if(children[c][node] == 0)
					{
						children[c][node] = nodeCount;
						nodeCount++;
					}
					
					node = children[c][node];
				}
				
				leaf[node] = 1;
			}
		}
		
		public void createDFA()
		{
			transition = new int[ALPHA][nodeCount];
			count = new int[nodeCount];
			
			ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
			queue.add(0);
			queue.add(0);
			
			while(queue.size() > 0)
			{
				int node = queue.remove();
				int suffLink = queue.remove();
				
				count[node] = leaf[node] + count[suffLink];
				
				for(int ch = 0; ch < ALPHA; ch++)
				{
					if(children[ch][node] != 0)
					{
						transition[ch][node] = children[ch][node];
						queue.add(children[ch][node]);
						queue.add(node == 0 ? 0 : transition[ch][suffLink]);
					}
					else
					{
						transition[ch][node] = transition[ch][suffLink];
					}
				}
			}
		}
	}
}
