#include <bits/stdc++.h>
using namespace std;
long long a[1000006], b[1000006], c[1000006], p[1000006], tree[1000005], n, k,
    ans = 0;
long long lowbit(long long x) { return x & (-x); }
void add(long long x) {
  while (x <= 1000000) {
    tree[x]++;
    x += lowbit(x);
  }
}
long long query(long long x) {
  long long res = 0;
  while (x > 0) {
    res += tree[x];
    x -= lowbit(x);
  }
  return res;
}
int main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    p[a[i]] = i;
  }
  for (long long i = 1; i <= k; i++) {
    scanf("%lld", &b[i]);
    c[b[i]]--;
  }
  vector<long long> num;
  set<long long> s;
  for (long long i = 1; i <= n; i++) {
    if (!c[i]) num.push_back(i);
  }
  s.insert(0);
  s.insert(n + 1);
  long long now = 1;
  for (auto i : num) {
    while (now <= n && now < i) s.insert(p[now++]);
    auto it = s.lower_bound(p[i]);
    long long r = *it, l = *(--it);
    if (r - 1 > 0) ans -= query(r - 1);
    if (l > 0) ans += query(l);
    add(p[i]);
    ans += r - l - 1;
    now++;
  }
  cout << ans << endl;
}
