#include <bits/stdc++.h>
using namespace std;
const int MAX_LEN = 1e6 + 10;
int n, m;
long long tree[MAX_LEN];
int id[MAX_LEN], keep[MAX_LEN];
void add(int pos, int value) {
  while (pos <= n) {
    tree[pos] += value;
    pos += (pos & -pos);
  }
  return;
}
long long query(int l, int r) {
  int ans = 0;
  while (r) {
    ans += tree[r];
    r -= (r & -r);
  }
  while (l) {
    ans -= tree[l];
    l -= (l & -l);
  }
  return ans;
}
set<int> se;
set<int> reverseSe;
int main() {
  memset(keep, false, sizeof(keep));
  scanf("%d%d", &n, &m);
  int tmp;
  for (int i = 1; i <= n; i++) scanf("%d", &tmp), id[tmp] = i;
  for (int i = 1; i <= m; i++) scanf("%d", &tmp), keep[tmp] = true;
  se.insert(0);
  se.insert(n + 1);
  reverseSe.insert(0);
  reverseSe.insert(-n - 1);
  if (n == m) {
    cout << 0 << endl;
    return 0;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (keep[i])
      se.insert(id[i]), reverseSe.insert(-id[i]);
    else {
      int l = -*reverseSe.upper_bound(-id[i]);
      int r = *se.upper_bound(id[i]);
      ans += r - l - 1;
      ans -= query(l, r - 1);
      add(id[i], 1);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
