#include <bits/stdc++.h>
using namespace std;
int n, q, k = 20;
pair<int, int> arr[2000042];
bool used[2000042];
int itSum[5000042], itMin[5000042], itMax[5000042];
void addSum(int ind, int v) {
  ind += (1 << k);
  itSum[ind] = v;
  for (ind >>= 1; ind; ind >>= 1) {
    itSum[ind] = itSum[ind * 2] + itSum[ind * 2 + 1];
  }
}
void addMM(int ind, int v) {
  ind += (1 << k);
  itMax[ind] = v;
  itMin[ind] = v;
  for (ind >>= 1; ind; ind >>= 1) {
    itMax[ind] = max(itMax[ind * 2], itMax[ind * 2 + 1]);
    itMin[ind] = min(itMin[ind * 2], itMin[ind * 2 + 1]);
  }
}
int getSum(int l, int r, int ll, int rr, int ind) {
  if (rr <= l || r <= ll) {
    return 0;
  }
  if (ll <= l && r <= rr) {
    return itSum[ind];
  }
  return getSum(l, (l + r) >> 1, ll, rr, ind * 2) +
         getSum((l + r) >> 1, r, ll, rr, ind * 2 + 1);
}
int getMin(int l, int r, int ll, int rr, int ind) {
  if (rr <= l || r <= ll) {
    return 1 << 20;
  }
  if (ll <= l && r <= rr) {
    return itMin[ind];
  }
  int crr = getMin(l, (l + r) >> 1, ll, rr, ind * 2);
  if (crr != 1 << 20) {
    return crr;
  }
  return getMin((l + r) >> 1, r, ll, rr, ind * 2 + 1);
}
int getMax(int l, int r, int ll, int rr, int ind) {
  if (rr <= l || r <= ll) {
    return -1;
  }
  if (ll <= l && r <= rr) {
    return itMax[ind];
  }
  int crr = getMax((l + r) >> 1, r, ll, rr, ind * 2 + 1);
  if (crr != -1) {
    return crr;
  }
  return getMax(l, (l + r) >> 1, ll, rr, ind * 2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  for (int i = 1; i < (1 << k + 1); i++) {
    itMin[i] = 1 << 20;
    itMax[i] = -1;
  }
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first;
    arr[i].second = i;
  }
  sort(arr, arr + n);
  for (int i = 0; i < q; i++) {
    int crr;
    cin >> crr;
    used[crr] = 1;
  }
  for (int i = 0; i < n; i++) {
    addSum(arr[i].second, 1);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int r = getMin(0, (1 << k), arr[i].second, n, 1),
        l = getMax(0, (1 << k), 0, arr[i].second, 1) + 1;
    if (r == (1 << 20)) {
      r = n;
    }
    if (!used[arr[i].first]) {
      ans += getSum(0, (1 << k), l, r, 1);
    } else {
      addMM(arr[i].second, arr[i].second);
    }
    addSum(arr[i].second, 0);
  }
  cout << ans << "\n";
  return 0;
}
