#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 5;
int n, k;
int pos[MAX_N], mp[MAX_N];
bool need[MAX_N];
set<int> My_set;
int bit[MAX_N];
int sum(int i) {
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}
void update(int i, int x) {
  while (i <= n) {
    bit[i] += x;
    i += i & -i;
  }
}
void input() {
  scanf("%d%d", &n, &k);
  memset(pos, 0, sizeof(pos));
  memset(need, 0, sizeof(need));
  int x;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    mp[i] = x;
    pos[x] = i;
  }
  for (int i = 1; i <= k; i++) {
    scanf("%d", &x);
    need[x] = 1;
  }
}
void solve() {
  My_set.clear();
  My_set.insert(0);
  My_set.insert(n + 1);
  for (int i = 1; i <= n; i++) update(i, 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (need[i]) {
      My_set.insert(pos[i]);
    } else {
      int x = pos[i];
      set<int>::iterator it_q = My_set.lower_bound(x);
      set<int>::iterator it_p = it_q;
      it_p--;
      int p = *it_p, q = *it_q;
      ans += sum(q - 1) - sum(p);
      update(x, -1);
    }
  }
  cout << ans << endl;
}
int main() {
  input();
  solve();
  return 0;
}
