f=input;s=f();l=len(s);d={*eval("f(),"*int(f()))};print(sum(sum(s[j:j+i+1]in d for j in range(l-i))for i in range(10)))