#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
const int lg = 20;
int pos[maxn];
bool vis[maxn];
int bit[maxn];
int loga[maxn];
int st[maxn][20];
void update(int idx, int val) {
  idx += 2;
  while (idx < maxn) {
    bit[idx] += val;
    idx += idx & (-idx);
  }
}
int query(int idx) {
  idx += 2;
  int sum = 0;
  while (idx) {
    sum += bit[idx];
    idx -= idx & (-idx);
  }
  return sum;
}
int query_min(int a, int b) {
  if (a > b) swap(a, b);
  int k = b - a + 1;
  return min(st[a][loga[k]], st[b - (1 << loga[k]) + 1][loga[k]]);
}
int n, k;
int get_left(int val) {
  int p = pos[val];
  int lo = 1;
  int hi = p;
  int ans = 0;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    int mi = query_min(mid, p);
    if (mi >= val) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  return ans;
}
int get_right(int val) {
  int p = pos[val];
  int lo = p;
  int hi = n;
  int ans = 0;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    int mi = query_min(p, mid);
    if (mi >= val) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  return ans;
}
const int inf = 1e9;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) loga[i] = 31 - __builtin_clz(i);
  for (int i = 1; i <= n; i++) {
    update(i, 1);
    int a;
    scanf("%d", &a);
    pos[a] = i;
    st[i][0] = inf;
  }
  for (int i = 1; i <= k; i++) {
    int a;
    scanf("%d", &a);
    vis[a] = 1;
    st[pos[a]][0] = a;
  }
  for (int i = 1; (1 << i) <= n; i++) {
    for (int j = 1; j + (1 << i) <= n + 1; j++) {
      st[j][i] = min(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    int l = get_left(i);
    int r = get_right(i);
    ans += query(r) - query(l - 1);
    update(pos[i], -1);
  }
  printf("%lld\n", ans);
  return 0;
}
