#include <bits/stdc++.h>
using namespace std;
set<int> s;
vector<pair<int, int> > v;
int fen[1000010];
bool marked[1000010];
void add(int v, int val) {
  for (; v > 0; v -= v & (-v)) fen[v] += val;
}
int get(int v) {
  int ans = 0;
  for (; v <= 1000010; v += v & (-v)) ans += fen[v];
  return ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    v.push_back(pair<int, int>(a, i));
    add(i, 1);
  }
  sort(v.begin(), v.end());
  for (int i = 1; i <= k; i++) {
    int b;
    cin >> b;
    marked[b] = true;
  }
  long long ans = 0;
  for (int i = 0; i < v.size(); i++)
    if (marked[v[i].first])
      s.insert(v[i].second);
    else {
      set<int>::iterator it = s.lower_bound(v[i].second);
      int lo, hi;
      if (it == s.end())
        hi = n + 1;
      else
        hi = *it;
      if (it == s.begin())
        lo = 1;
      else {
        it--;
        lo = *it + 1;
      }
      ans += get(lo) - get(hi);
      add(v[i].second, -1);
    }
  cout << ans << endl;
}
