human
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature will appear in the nearest update, when developers faced some troubles that only you may help them to solve.

All the messages are represented as a strings consisting of only lowercase English letters. In order to reduce the network load strings are represented in the special compressed form. Compression algorithm works as follows: string is represented as a concatenation of n blocks, each block containing only equal characters. One block may be described as a pair (li, ci), where li is the length of the i-th block and ci is the corresponding letter. Thus, the string s may be written as the sequence of pairs .

Your task is to write the program, that given two compressed string t and s finds all occurrences of s in t. Developers know that there may be many such occurrences, so they only ask you to find the number of them. Note that p is the starting position of some occurrence of s in t if and only if tptp + 1...tp + |s| - 1 = s, where ti is the i-th character of string t.

Note that the way to represent the string in compressed form may not be unique. For example string "aaaa" may be given as , , ...

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of blocks in the strings t and s, respectively.

The second line contains the descriptions of n parts of string t in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.

The second line contains the descriptions of m parts of string s in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.

Output

Print a single integer — the number of...
def c
assistant
#Here is Python program to find the number of them.
ompress(bstr):
    pk, pc = None, None

    for block in bstr:
        if pc is None:
            pk, pc = block
        elif pc == block[1]:
            pk += block[0]
        else:
            yield  pk, pc
            pk, pc = block

    if pc is not None:
        yield pk, pc

def find1(text, query):
    (bk, bc), = query
    return sum(k-bk+1 for k, c in text if c == bc and k >= bk)

class Query:
    def __init__(self, query):
        self._query = query
        self._len = len(query)
        self._suffixes = [None]

    def _suffix(self, i, pblock=None):
        if i is None:
            return None

        for j in range(len(self._suffixes), min(i+1, self._len-1)):
            self._suffixes.append(
                self.next(self._suffixes[j-1], self._query[j]))

        if i < self._len - 1:
            return self._suffixes[i]
        else:
            return self.next(self._suffixes[i-1], pblock)

    def _match(self, i, block):
        if i == 0 or i == self._len -1:
            return (block[1] == self._query[i][1]
                    and block[0] >= self._query[i][0])
        else:
            return block == self._query[i]

    def next(self, i, block, pblock=None):
        while True:
            if i is None:
                return 0 if self._match(0, block) else None
            elif i < self._len-1:
                if self._match(i+1, block):
                    return i+1
                else:
                    i = self._suffix(i)
            else:
                i = self._suffix(i, pblock)
                pblock = None

    def is_match(self, i):
        return i == self._len-1

def find2(text, query):
    qobj = Query(query)
    i = None
    pblock = None
    c = 0
    for block in text:
        i, pblock = qobj.next(i, block, pblock), block
        if qobj.is_match(i):
            c += 1
    return c

def find(text, query):
    text = list(compress(text))
    query = list(compress(query))
    return (find1 if len(query) == 1 else find2)(text, query)

def parse_block(s):
    k, c...