class String
	def suffix_array
		buckets = {}
		(0..size-1).each do |i|
			(buckets[self[i]] ||= []) << i
		end	
		index_table = []
		r = 0
		rank = []
		buckets.keys.sort.each do |c|
			buckets[c].each do |i|
				rank[i] = r + buckets[c].size - 1
			end
			r += buckets[c].size
			index_table << buckets[c].pop until buckets[c].empty?
		end

		d = 1
		loop do
			i = 0
			loop do
				j = index_table[i]
				r = rank[j]
				if i == r
					i += 1
				else
					index_table.sa_sort!(i, r, rank, d)
					i = r + 1
				end
				break if i >= size
			end
			d <<= 1
			break if d >= self.size
		end

		index_table
	end	
end

class Array
	def sa_sort!(l, r, rank, d)
		if r <= l
			if l == r
				rank[self[l]] = l
			end
			return
		end
		pivot_idx = self[rand(r-l+1) + l]
		pivot_rank = (rank[pivot_idx + d] || -1)

		lesser = l
		greater = r
		i = l
		loop do
			break if i > greater
			target_rank = (rank[self[i] + d] || -1)
			if target_rank < pivot_rank
				self[i], self[lesser] = self[lesser], self[i]
				lesser += 1
				i += 1
			elsif target_rank > pivot_rank
		 		self[i], self[greater] = self[greater], self[i]
		 		greater -= 1
			else
				i += 1
			end
		end

		raise if greater < 0
		sa_sort!(l, lesser-1, rank, d)
		(lesser..greater).each do |i|
			rank[self[i]] = greater
		end
		sa_sort!(greater+1, r, rank, d)
	end

	def bsearch_first_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_first_index(l, c-1, &pred) || c
		else
			bsearch_first_index(c+1, r, &pred)
		end
	end

	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end
end

require 'set'
n, m = gets.split.map(&:to_i)
str = gets.chomp
sa = str.suffix_array

size_idx = {}
l = r = 0
m.times do
	query = gets.chomp.downcase[0..-2] + "=1"
	eval query
	(size_idx[r - l] ||= Set.new) << l
end

num = 0
size_idx.each do |size, indices|
	used = Set.new
	indices.each do |l|
		next if used.include?(l)
		num += 1
		substr = str[l..l+size]
		i = sa.bsearch_first_index {|k| substr <= str[k..k+size]}
		j = sa.bsearch_last_index {|k| str[k..k+size] <= substr}
		sa[i..j].each {|x| used << x}
	end
end

p num