#include <bits/stdc++.h>
using namespace std;
int P[1000007];
int B[1000007];
int stayCnt[1000007];
int Lstop[1000007];
int Rstop[1000007];
bool stay[1000007];
int posX[1000007];
int strom[1000007];
void pricti(unsigned int index, int rozdil) {
  while (index <= 1000000) {
    strom[index] += rozdil;
    index = index + (index & -index);
  }
}
int prefSoucet(unsigned int index) {
  int soucet = 0;
  while (index > 0) {
    soucet = soucet + strom[index];
    index = index & (index - 1);
  }
  return soucet;
}
int main() {
  int N, K;
  scanf("%d %d ", &N, &K);
  ;
  for (int i = (0); i < (N); i++) {
    cin >> P[i];
    stay[P[i]] = false;
  }
  for (int i = (0); i < (K); i++) {
    cin >> B[i];
    stay[B[i]] = true;
  }
  vector<int> num;
  vector<int> pos;
  int len = 0;
  for (int i = (0); i < (N); i++) {
    if (stay[P[i]]) {
      int idx = lower_bound(num.begin(), num.begin() + len, P[i]) - num.begin();
      if (idx >= num.size()) {
        num.push_back(P[i]);
        pos.push_back(i);
        len++;
      }
      num[idx] = P[i];
      pos[idx] = i;
      len = idx + 1;
    } else {
      int idx = lower_bound(num.begin(), num.begin() + len, P[i]) - num.begin();
      if (idx == 0)
        Lstop[i] = 0;
      else
        Lstop[i] = pos[idx - 1] + 1;
    }
  }
  num.clear();
  pos.clear();
  len = 0;
  for (int i = (N - 1); i >= (0); i--) {
    if (stay[P[i]]) {
      int idx = lower_bound(num.begin(), num.begin() + len, P[i]) - num.begin();
      if (idx >= num.size()) {
        num.push_back(P[i]);
        pos.push_back(i);
        len++;
      }
      num[idx] = P[i];
      pos[idx] = i;
      len = idx + 1;
    } else {
      int idx = lower_bound(num.begin(), num.begin() + len, P[i]) - num.begin();
      if (idx == 0) {
        Rstop[i] = N - 1;
      } else {
        Rstop[i] = pos[idx - 1] - 1;
      }
    }
  }
  for (int i = (0); i < (N); i++) posX[P[i]] = i;
  long long sum = 0;
  for (int i = (1); i < (N + 1); i++) {
    if (!stay[i]) {
      int p = posX[i];
      sum += (long long)(Rstop[p] - Lstop[p] + 1 -
                         (prefSoucet(Rstop[p] + 1) -
                          prefSoucet(Lstop[p] + 1 - 1)));
      pricti(p + 1, 1);
    }
  }
  cout << sum << endl;
  return 0;
}
