#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int p[maxn], b[maxn], tree[maxn];
int n, k, a;
void add(int x, int v) {
  while (x <= n) {
    tree[x] += v;
    x += x & (-x);
  }
}
long long sum(int x) {
  int ans = 0;
  while (x > 0) {
    ans += tree[x];
    x -= x & (-x);
  }
  return ans;
}
void solve() {
  set<int> s;
  set<int>::iterator iter;
  long long ans = 0;
  s.insert(0), s.insert(n + 1);
  for (int i = 1; i <= n; i++) {
    if (b[i]) {
      s.insert(p[i]);
      continue;
    }
    iter = s.upper_bound(p[i]);
    int r = *iter - 1;
    int l = *(--iter);
    ans += sum(r) - sum(l);
    add(p[i], -1);
  }
  cout << ans << endl;
}
int main() {
  cin >> n >> k;
  memset(tree, 0, sizeof(tree));
  memset(b, 0, sizeof(b));
  memset(p, 0, sizeof(p));
  for (int i = 1; i <= n; i++) {
    cin >> a;
    p[a] = i;
    add(i, 1);
  }
  for (int i = 1; i <= k; i++) {
    cin >> a;
    b[a] = 1;
  }
  solve();
  return 0;
}
