#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e6 + 10;
int pos[MAXN];
int a[MAXN], vis[MAXN], n, k, b[MAXN];
long long c[MAXN];
set<int> position;
void add(int pos, int v) {
  while (pos <= n) {
    c[pos] += v;
    pos += pos & -pos;
  }
}
long long getsum(int pos) {
  long long ret = 0;
  while (pos > 0) {
    ret += c[pos];
    pos -= pos & -pos;
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i), pos[a[i]] = i;
  for (int i = 1; i <= k; i++) scanf("%d", b + i), vis[b[i]] = true;
  long long ans = 0;
  position.insert(0);
  position.insert(n + 1);
  for (int i = 1; i <= n; i++) add(i, 1);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      int right = (*position.upper_bound(pos[i]));
      int left = *(--position.lower_bound(pos[i]));
      ans += getsum(right - 1) - getsum(left);
      add(pos[i], -1);
    } else
      position.insert(pos[i]);
  cout << ans << endl;
  return 0;
}
