#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  char s[200005];
  long long ck[130] = {0};
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < k; i++) {
    char ch;
    cin >> ch;
    ck[ch] = 1;
  }
  long long cnt = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    if (ck[s[i]]) {
      cnt++;
    } else {
      sum += (cnt * (cnt + 1)) / 2;
      cnt = 0;
    }
  }
  sum += (cnt * (cnt + 1)) / 2;
  cout << sum;
  cout << "\n";
  return 0;
}
