from collections import defaultdict def get_input(): s = str(input()) m = int(input()) c = [str(input()) for i in range(m)] return s, m, c if __name__ == "__main__": s, m, c = get_input() count = 0 s_id = defaultdict(lambda:len(s_id)+1) for ci in c: len_c = len(ci) first, target = 0, 0 for i in range(len_c): target += s_id[ci[i]] * 10**(len_c - i - 1) first += s_id[s[i]] * 10**(len_c - i - 1) if first == target: count += 1 for i in range(len_c,len(s)): first = (first % 10**(len_c -1 )) * 10 + s_id[s[i]] if target == first: count += 1 print(count)