#include <bits/stdc++.h>
using namespace std;
set<int> s;
int i, n, k, f[1010101], g[1010101], pos1[1010101], d[1010101], need[1010101];
void modify(int x) {
  while (x <= n) {
    d[x]++;
    x += x & -x;
  }
}
int getsum(int x) {
  int sum = 0;
  while (x > 0) {
    sum += d[x];
    x -= x & -x;
  }
  return sum;
}
int main() {
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%d", f + i);
    pos1[f[i]] = i;
  }
  for (i = 1; i <= k; i++) {
    scanf("%d", g + i);
    need[g[i]] = 1;
  }
  long long ans = 0;
  s.insert(0);
  s.insert(n + 1);
  for (i = 1; i <= n; i++) {
    if (need[i]) {
      s.insert(pos1[i]);
    } else {
      int l, r;
      l = *(--s.lower_bound(pos1[i])) + 1;
      r = *(s.upper_bound(pos1[i])) - 1;
      ans += r - l + 1 - getsum(r) + getsum(l - 1);
      modify(pos1[i]);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
