#include <bits/stdc++.h>
using namespace std;
int c[1000005], n, m;
int Hash[1000005], pos[1000005];
int lowbit(int x) { return x & -x; }
void add(int pos, int val) {
  while (pos <= n) {
    c[pos] += val;
    pos += lowbit(pos);
  }
}
int getsum(int pos) {
  int ans = 0;
  while (pos) {
    ans += c[pos];
    pos -= lowbit(pos);
  }
  return ans;
}
int main() {
  int i, j, x, l, r;
  long long ans;
  set<int> iset;
  while (scanf("%d%d", &n, &m) != EOF) {
    ans = 0;
    memset(c, 0, sizeof(c));
    memset(Hash, 0, sizeof(Hash));
    (iset).clear();
    for (i = 1; i <= n; i++) {
      scanf("%d", &x);
      pos[x] = i;
    }
    for (i = 1; i <= m; i++) {
      scanf("%d", &x);
      Hash[x] = 1;
    }
    iset.insert(0);
    iset.insert(n + 1);
    for (i = 1; i <= n; i++) {
      if (Hash[i])
        iset.insert(pos[i]);
      else {
        r = *iset.lower_bound(pos[i]), l = *--iset.lower_bound(pos[i]);
        r--, l++;
        ans += r - l + 1 - (getsum(r) - getsum(l - 1));
        add(pos[i], 1);
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
