#include <bits/stdc++.h>
using namespace std;
int n, k;
const int max_n = 1e6 + 5;
int pos[max_n];
bool mark[max_n];
set<int> s;
set<int>::iterator it;
namespace BIT {
int c[max_n];
inline void modify(int p, int v) {
  if (p > 0) {
    for (int i = p; i <= n; i += i & (-i)) c[i] += v;
  }
}
inline int query(int p) {
  int res = 0;
  for (int i = p; i > 0; i -= i & (-i)) res += c[i];
  return res;
}
}  // namespace BIT
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    pos[p] = i;
  }
  for (int i = 1; i <= k; ++i) {
    int b;
    scanf("%d", &b);
    mark[b] = true;
  }
  for (int i = 1; i <= n; ++i) BIT::modify(i, 1);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (mark[i])
      s.insert(pos[i]);
    else {
      int l = 1, r = n;
      it = s.lower_bound(pos[i]);
      if (it != s.end()) r = *it - 1;
      if (it != s.begin()) l = *(--it) + 1;
      ans += BIT::query(r) - BIT::query(l - 1);
      BIT::modify(pos[i], -1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
