#include <bits/stdc++.h>
using namespace std;
vector<int> fen;
int size;
void init(int n) {
  size = n;
  fen.assign(n, 0);
}
int sum(int i) {
  int res = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) res += fen[i];
  return res;
}
int sum(int l, int r) { return sum(r) - sum(l - 1); }
void inc(int i, int delta) {
  for (; i < size; i = (i | (i + 1))) fen[i] += delta;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> pos(n, 0);
  vector<bool> need(n, false);
  init(n);
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    pos[--t] = i;
    inc(i, 1);
  }
  for (int j = 0; j < k; j++) {
    int t;
    cin >> t;
    need[--t] = true;
  }
  set<int> lessPos;
  lessPos.insert(-1);
  lessPos.insert(n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (need[i]) {
      lessPos.insert(pos[i]);
    } else {
      int rightBound = *(lessPos.lower_bound(pos[i])) - 1,
          leftBound = *(--lessPos.lower_bound(pos[i])) + 1;
      ans += sum(leftBound, rightBound);
      inc(pos[i], -1);
    }
  }
  cout << ans;
  return 0;
}
