#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int fenw[MAXN];
bool u[MAXN];
int m[MAXN];
int n, k;
long long ans;
int f(int x) { return x & -x; }
int prefSum(int x) {
  int ret = 0;
  for (; x > 0; x -= f(x)) {
    ret += fenw[x];
  }
  return ret;
}
void fenwUpd(int x, int v) {
  for (; x <= n; x += f(x)) {
    fenw[x] += v;
  }
}
int segSum(int l, int r) { return prefSum(r) - prefSum(l - 1); }
void solve() {
  scanf("%d %d", &n, &k);
  for (int i = 1, x; i <= n; ++i) {
    scanf("%d", &x);
    m[x] = i;
  }
  for (int i = 1, x; i <= k; ++i) {
    scanf("%d", &x);
    u[x] = 1;
  }
  set<int> ms;
  ms.insert(1);
  ms.insert(n + 1);
  for (int i = 1; i <= n; ++i) {
    fenwUpd(i, 1);
  }
  for (int i = 1; i <= n; ++i) {
    int x = m[i];
    auto it = --ms.upper_bound(x);
    if (u[i]) {
      ms.insert(x);
      ms.insert(x + 1);
    } else {
      int l = *it, r = *(++it) - 1;
      ans += segSum(l, r);
      fenwUpd(x, -1);
    }
  }
  printf("%lld\n", ans);
}
int main() {
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
