#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int a[N], pos[N], st[4 * N], keep[N];
set<int> s;
void update(int ss, int se, int ind, int val, int i) {
  if (ss > se || se < ind || ss > ind) return;
  if (ss == se) {
    st[i] = val;
    return;
  }
  int mid = (ss + se) / 2;
  update(ss, mid, ind, val, 2 * i + 1);
  update(mid + 1, se, ind, val, 2 * i + 2);
  st[i] = st[2 * i + 1] + st[2 * i + 2];
}
int query(int ss, int se, int l, int r, int i) {
  if (ss > se || ss > r || se < l) return 0;
  if (l <= ss && se <= r) return st[i];
  int mid = (ss + se) / 2;
  return query(ss, mid, l, r, 2 * i + 1) + query(mid + 1, se, l, r, 2 * i + 2);
}
int main() {
  int n, k, i, x;
  long long ans = 0;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d", a + i);
    pos[a[i]] = i;
    update(0, n - 1, i, 1, 0);
  }
  for (i = 0; i < k; ++i) {
    scanf("%d", &x);
    keep[x] = true;
  }
  for (i = 1; i <= n; i++) {
    if (keep[i])
      s.insert(pos[i]);
    else {
      auto it = s.lower_bound(pos[i]);
      int en = n - 1, st = 0;
      if (it != s.end()) en = *it - 1;
      if (it != s.begin() && s.size()) st = *(--it) + 1;
      ans += query(0, n - 1, st, en, 0);
      update(0, n - 1, pos[i], 0, 0);
    }
  }
  cout << ans;
}
