#include <bits/stdc++.h>
using namespace std;
const int BUF = 1000005;
class Data {
 public:
  int v, idx;
  bool toLeft;
  Data() {}
  Data(int v, int idx, bool toLeft) : v(v), idx(idx), toLeft(toLeft) {}
  bool operator<(const Data &opp) const { return v < opp.v; }
};
class SegTree {
 public:
  int v[BUF * 4];
  SegTree() { memset(v, 0, sizeof(v)); }
  int init(int node, int L, int R) {
    if (L == R) return v[node] = 1;
    int s = init(node * 2 + 1, L, (L + R) / 2);
    int t = init(node * 2 + 2, (L + R) / 2 + 1, R);
    return v[node] = s + t;
  }
  int get(int node, int L, int R, int LQ, int RQ) {
    if (R < LQ || RQ < L) return 0;
    if (LQ <= L && R <= RQ) return v[node];
    int s = get(node * 2 + 1, L, (L + R) / 2, LQ, RQ);
    int t = get(node * 2 + 2, (L + R) / 2 + 1, R, LQ, RQ);
    return s + t;
  }
  int update(int node, int L, int R, int Q, int chVal) {
    if (R < Q || Q < L) return v[node];
    if (L == R) return v[node] = chVal;
    int s = update(node * 2 + 1, L, (L + R) / 2, Q, chVal);
    int t = update(node * 2 + 2, (L + R) / 2 + 1, R, Q, chVal);
    return v[node] = s + t;
  }
};
int nVal, val[BUF];
int nLeft, toLeft[BUF];
void read() {
  scanf("%d%d", &nVal, &nLeft);
  for (int i = 0; i < nVal; ++i) scanf("%d", &val[i]);
  for (int i = 0; i < nLeft; ++i) scanf("%d", &toLeft[i]);
}
void work() {
  vector<Data> dataList;
  for (int i = 0, j = 0; i < nVal; ++i)
    if (j != nLeft && val[i] == toLeft[j]) {
      dataList.push_back(Data(val[i], i, true));
      ++j;
    } else {
      dataList.push_back(Data(val[i], i, false));
    }
  sort(dataList.begin(), dataList.end());
  static SegTree stree;
  stree = SegTree();
  stree.init(0, 0, nVal - 1);
  set<int> S;
  long long ans = 0;
  for (int i = 0; i < nVal; ++i) {
    Data &data = dataList[i];
    if (data.toLeft) {
      S.insert(data.idx);
    } else {
      set<int>::iterator it1 = S.upper_bound(data.idx);
      set<int>::iterator it2 = it1;
      if (!S.empty()) --it2;
      int dst = it1 == S.end() ? nVal : *it1;
      int src = S.empty() || it1 == S.begin() ? -1 : *it2;
      ans += stree.get(0, 0, nVal - 1, src + 1, dst - 1);
      stree.update(0, 0, nVal - 1, data.idx, 0);
    }
  }
  cout << ans << endl;
}
int main() {
  read();
  work();
  return 0;
}
