#include <bits/stdc++.h>
using namespace std;
int n, k, a[1000005], t[1000005];
long long ans;
bool b[1000005];
struct node {
  int l, r;
};
bool operator<(node x, node y) { return x.r < y.r; }
set<node> s;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x + (x << 2) << 1) + (ch ^ 48);
  return x * f;
}
int query(int x) {
  int ans = 0;
  while (x) ans += t[x], x &= x - 1;
  return ans;
}
void add(int x) {
  while (x <= n) t[x]++, x += x & -x;
}
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    a[x] = i;
  }
  for (int i = 1; i <= k; i++) {
    int x = read();
    b[x] = 1;
  }
  s.insert((node){1, n});
  for (int i = 1; i <= n; i++) {
    node x = *s.lower_bound((node){a[i], a[i]});
    if (b[i]) {
      s.erase(x);
      if (a[i] > x.l) s.insert((node){x.l, a[i] - 1});
      if (a[i] < x.r) s.insert((node){a[i] + 1, x.r});
    } else
      ans += x.r - x.l + 1 - query(x.r) + query(x.l - 1);
    add(a[i]);
  }
  printf("%lld", ans);
  return 0;
}
