#include <bits/stdc++.h>
using namespace std;
const int N = ((1e6) + 10);
int tree[N];
int n;
void inc(int i, int val) {
  for (int j = i; j < n + 10; j = (j | j + 1)) {
    tree[j] += val;
  }
}
int sum(int index) {
  int sum = 0;
  for (int i = index; i >= 0; i = ((i & (i + 1)) - 1)) sum += tree[i];
  return sum;
}
int sumRange(int l, int r) { return sum(r) - sum(l - 1); }
int main() {
  int k, val;
  scanf("%d %d", &n, &k);
  int perm[n];
  int need[n];
  set<int> S;
  for (int i = 0; i < n; i++) {
    scanf("%d", &val);
    perm[val] = i;
  }
  for (int i = 0; i < k; i++) {
    scanf("%d", &val);
    need[val] = 1;
  }
  unsigned long long result = 0;
  int l, r;
  for (int i = 1; i <= n + 1; i++) {
    if (need[i] == 1)
      S.insert(perm[i]);
    else {
      set<int>::iterator it = S.upper_bound(perm[i]);
      l = -1, r = n;
      if (it != S.end()) r = *it;
      if (it != S.begin()) {
        --it;
        l = *it;
      }
      result += r - l - 1 - sumRange(l, r);
      inc(perm[i], 1);
    }
  }
  cout << result << endl;
  return 0;
}
