n, m = gets.split.map &:to_i
s = gets.chomp
l = r = 0
ranges = (1..m).map {
	eval gets.downcase.sub(/.\n/, "=1")
	[l, r]
}
ranges.uniq!
ranges.sort!

start = {}
count = 0
until ranges.empty?
	l = ranges[0][0]
	r0 = l-1
	v = start
	while !ranges.empty? && ranges[0][0] == l
		_, r = ranges.shift
		(r0+1..r).each {|i|
			v = (v[s[i]] ||= {})
		}
		count += 1 unless v[:appeared]  
		v[:appeared] = 1	
		r0 = r
	end
end

p count