#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n;
int k;
int p[2 * N];
bool surv[2 * N];
int b[2 * N];
int ind[N];
int pre[2 * N];
int nex[2 * N];
int freq[2 * N];
int fQuery(int p) {
  if (p < 0) return 0;
  int res = 0;
  for (p += n; p > 0; p >>= 1) res += freq[p];
  return res;
}
void fModify(int l, int r, int value) {
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) freq[l++] += value;
    if (r & 1) freq[--r] += value;
  }
}
int pQuery(int p) {
  if (p < 0) return 0;
  int res = 0;
  for (p += n; p > 0; p >>= 1) res += pre[p];
  return res;
}
void pModify(int l, int r, int value) {
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) pre[l++] += value;
    if (r & 1) pre[--r] += value;
  }
}
int nQuery(int p) {
  if (p < 0) return 0;
  int res = 0;
  for (p += n; p > 0; p >>= 1) res += nex[p];
  return res;
}
void nModify(int l, int r, int value) {
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) nex[l++] += value;
    if (r & 1) nex[--r] += value;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    ind[p[i]] = i;
    surv[i] = false;
    fModify(i, n, 1);
  }
  pModify(0, n, -1);
  nModify(0, n, n);
  for (int i = 0; i < k; i++) {
    cin >> b[i];
    surv[ind[b[i]]] = true;
  }
  int sta, en;
  for (int i = 1; i <= n; i++) {
    int j = ind[i];
    if (surv[j]) {
      int pQ = pQuery(j);
      int nQ = nQuery(j);
      pModify(j, nQ, j - pQ);
      nModify(pQ + 1, j + 1, j - nQ);
    } else {
      sta = pQuery(j) - 1;
      en = nQuery(j) - 1;
      ans += fQuery(en) - fQuery(sta);
    }
    fModify(j, n, -1);
  }
  cout << ans << endl;
  return 0;
}
