#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[1000010], b[1000010], id[1000010];
bool keep[1000010];
int lmost[1000010], rmost[1000010];
int f[1000010];
void updateL(int i, int val) {
  for (; i <= n; i += i & -i) f[i] = max(f[i], val);
}
int getL(int i) {
  int ret = 0;
  for (; i; i -= i & -i) ret = max(ret, f[i]);
  return ret;
}
void updateR(int i, int val) {
  for (; i <= n; i += i & -i) f[i] = min(f[i], val);
}
int getR(int i) {
  int ret = n + 1;
  for (; i; i -= i & -i) ret = min(ret, f[i]);
  return ret;
}
void update(int i, int val) {
  for (; i <= n; i += i & -i) f[i] += val;
}
int get(int i) {
  int ret = 0;
  for (; i; i -= i & -i) ret += f[i];
  return ret;
}
bool cmp(int i, int j) { return a[i] < a[j]; }
int main() {
  scanf("%d%d", &n, &k);
  a[0] = a[n + 1] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    id[a[i]] = i;
  }
  for (int i = 1; i <= k; i++) {
    scanf("%d", b + i);
    keep[id[b[i]]] = 1;
  }
  k = 0;
  for (int i = 1; i <= n; i++)
    if (!keep[i]) b[++k] = i;
  sort(b + 1, b + 1 + k, cmp);
  memset(f, 0, sizeof f);
  for (int i = 1; i <= n; i++)
    if (keep[i])
      updateL(a[i], i);
    else {
      lmost[i] = getL(a[i] - 1);
      if (a[lmost[i]] < a[i]) lmost[i]++;
    }
  memset(f, 63, sizeof f);
  for (int i = n; i >= 1; i--)
    if (keep[i])
      updateR(a[i], i);
    else {
      rmost[i] = getR(a[i] - 1);
      if (a[rmost[i]] < a[i]) rmost[i]--;
    }
  memset(f, 0, sizeof f);
  for (int i = 1; i <= n; i++)
    if (keep[i]) update(i, 1);
  long long ret = 0;
  for (int i = k; i >= 1; i--) {
    update(b[i], 1);
    ret += get(rmost[b[i]]) - get(lmost[b[i]] - 1);
  }
  printf("%I64d", ret);
  return 0;
}
