// Arup Guha
// 2/18/2024
// Solution to 2023 UCF HS Online Contest Problem: Daniel's JUSTified Dilemma

import java.util.*;

public class just {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int n = Integer.parseInt(stdin.nextLine());
		char[][] words = new char[n][]; 
		
		// Get whole string.
		char[] s = stdin.nextLine().trim().toCharArray();
		
		// Add indexes for each letter in appropriate list.
		// -1 means that there isn't that letter any earlier...
		TreeSet<Integer>[] ts = new TreeSet[26];
		for (int i=0; i<26; i++) {
			ts[i] = new TreeSet<Integer>();
			ts[i].add(-1);
		}
		
		for (int i=0; i<s.length; i++) 
			if (s[i]>='a' && s[i]<='z')
				ts[s[i]-'a'].add(i);
		
		// Get words.
		for (int i=0; i<n; i++) 
			words[i] = stdin.nextLine().trim().toCharArray();
			
		// I'll make this 1-based, so dp[0] is for 0 chars.
		int[] dp = new int[s.length+1];
		
		// Fill in DP array.
		for (int i=1; i<=s.length; i++) {
		
			// We can do at least this good.
			dp[i] = dp[i-1];
		
			// Try matching this word here.
			for (char[] word: words) {
			
				int len = word.length;
				if (word[len-1] != s[i-1]) continue;
				
				// Returns the index of the start of this word as a subsequence.
				int prevIdx = getStart(ts, word, i-1);
				
				if (prevIdx == -1) continue;
				
				// Take the better of the old answer or building off this one.
				dp[i] = Math.max(dp[i], dp[prevIdx]+1);
			}
		}
		
		// Ta da!
		System.out.println(dp[dp.length-1]);
	}
	
	public static int getStart(TreeSet<Integer>[] ts, char[] word, int idx) {
	
		// Because of how I call this function, this is true.
		if (word.length == 1) return idx;
		
		for (int i=word.length-2; i>=0; i--) {
			
			idx = ts[word[i]-'a'].lower(idx);
			
			// Can't find it.
			if (idx == -1) return -1;
		}
		
		// If we get here, we found the subsequence.
		return idx;
	}
}