#include <bits/stdc++.h>
using namespace std;
int seg[1 << 21], mp[1000002], pos[1000002];
int seg2[1 << 21], mp2[1000002];
bool removable[1000002];
void shi(int l, int r, int i) {
  if (l == r) {
    mp[l] = i;
    return;
  }
  int mid = (l + r) >> 1;
  shi(l, mid, 2 * i + 1);
  shi(mid + 1, r, 2 * i + 2);
}
void put(int pos) {
  int i = mp[pos];
  seg[i] = 1;
  while (i > 0) {
    i = (i - 1) / 2;
    seg[i] = seg[2 * i + 1] + seg[2 * i + 2];
  }
}
int qkth(int l, int r, int k, int i) {
  if (l == r) return l;
  int mid = (l + r) >> 1;
  if (seg[2 * i + 1] >= k)
    return qkth(l, mid, k, 2 * i + 1);
  else
    return qkth(mid + 1, r, k - seg[2 * i + 1], 2 * i + 2);
}
int qsum(int l, int r, int a, int b, int i) {
  if (l > b || r < a || a > b) return 0;
  if (l >= a && r <= b) return seg[i];
  int mid = (l + r) >> 1;
  return qsum(l, mid, a, b, 2 * i + 1) + qsum(mid + 1, r, a, b, 2 * i + 2);
}
void shi2(int l, int r, int i) {
  if (l == r) {
    mp2[l] = i;
    seg2[i] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  shi2(l, mid, 2 * i + 1);
  shi2(mid + 1, r, 2 * i + 2);
  seg2[i] = seg2[2 * i + 1] + seg2[2 * i + 2];
}
void take(int pos) {
  int i = mp2[pos];
  seg2[i] = 0;
  while (i > 0) {
    i = (i - 1) / 2;
    seg2[i] = seg2[2 * i + 1] + seg2[2 * i + 2];
  }
}
int qsum2(int l, int r, int a, int b, int i) {
  if (l > b || r < a || a > b) return 0;
  if (l >= a && r <= b) return seg2[i];
  int mid = (l + r) >> 1;
  return qsum2(l, mid, a, b, 2 * i + 1) + qsum2(mid + 1, r, a, b, 2 * i + 2);
}
vector<int> lst;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  lst.push_back(0);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    pos[a] = i;
    removable[a] = 1;
    lst.push_back(a);
  }
  lst.push_back(n + 1);
  for (int i = 1; i <= k; i++) {
    int b;
    scanf("%d", &b);
    removable[b] = 0;
  }
  shi(0, n + 1, 0);
  shi2(0, n + 1, 0);
  put(0);
  put(n + 1);
  sort(lst.begin(), lst.end());
  long long ret = 0;
  for (int i = 1; i <= n; i++) {
    if (removable[lst[i]]) {
      int ind = pos[lst[i]];
      int lsum = qsum(0, n + 1, 0, ind, 0);
      int lpiv = qkth(0, n + 1, lsum, 0);
      int rpiv = qkth(0, n + 1, lsum + 1, 0);
      ret += qsum2(0, n + 1, lpiv + 1, rpiv - 1, 0);
      take(ind);
    } else
      put(pos[lst[i]]);
  }
  printf("%I64d", ret);
  return 0;
}
