#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5, inf = 1e9 + 7;
int n, k, a[maxn], b[maxn], v[maxn], l[maxn], r[maxn], c[maxn];
struct bit {
  int b[maxn], n;
  bit(int _n) {
    n = _n;
    for (int i = 0; i < n; i++) b[i] = inf;
  }
  int query(int idx) {
    idx++;
    int ans = inf;
    while (idx) {
      ans = min(ans, b[idx]);
      idx -= idx & (-idx);
    }
    return ans;
  }
  void update(int idx, int k) {
    idx++;
    while (idx <= n) {
      b[idx] = min(b[idx], k);
      idx += idx & (-idx);
    }
  }
} L(maxn - 1), R(maxn - 1);
struct bit2 {
  int b[maxn], n;
  bit2(int _n) {
    n = _n;
    memset(b, 0, (n) * sizeof(int));
  }
  int query(int idx) {
    idx++;
    int ans = 0;
    while (idx) {
      ans = ans + b[idx];
      idx -= idx & (-idx);
    }
    return ans;
  }
  void update(int idx, int k) {
    idx++;
    while (idx <= n) {
      b[idx] = (b[idx] + k);
      idx += idx & (-idx);
    }
  }
} C(maxn - 1);
vector<int> le[maxn], re[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < k; i++) {
    cin >> b[i];
    v[b[i]] = 1;
  }
  for (int i = 0; i < n; i++)
    if (!v[a[i]]) {
      l[i] = L.query(a[i]);
      if (l[i] >= inf)
        l[i] = 0;
      else
        l[i] = -l[i] + 1;
      le[l[i]].push_back(i);
    } else
      L.update(a[i], -i);
  for (int i = n - 1; i >= 0; i--)
    if (!v[a[i]]) {
      r[i] = R.query(a[i]);
      if (r[i] >= inf)
        r[i] = n - 1;
      else
        r[i]--;
      re[r[i]].push_back(i);
    } else
      R.update(a[i], i);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < le[i].size(); j++) {
      int jdx = le[i][j];
      c[jdx] = -C.query(a[jdx] - 1);
    }
    if (!v[a[i]]) C.update(a[i], 1);
    for (int j = 0; j < re[i].size(); j++) {
      int jdx = re[i][j];
      c[jdx] += C.query(a[jdx] - 1);
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++)
    if (!v[a[i]]) {
      ans += r[i] - l[i] + 1 - c[i];
    }
  cout << ans << endl;
  return 0;
}
