#include <bits/stdc++.h>
using namespace std;
vector<int> st;
vector<int> p;
const int INF = 2e7;
void update(int v, int tl, int tr, int pos) {
  if (tl == tr) {
    st[v] = INF;
    return;
  }
  int m = (tl + tr) >> 1;
  int vl = v * 2 + 1;
  int vr = v * 2 + 2;
  if (pos <= m) {
    update(vl, tl, m, pos);
  } else {
    update(vr, m + 1, tr, pos);
  }
  st[v] = min(st[vl], st[vr]);
}
pair<int, int> getBorders(int v, int tl, int tr, int pos, int val) {
  if (st[v] >= val) {
    return make_pair(tl, tr);
  }
  if (tl == tr) {
    return make_pair(tl + 1, tr - 1);
  }
  int m = (tl + tr) >> 1;
  int vl = v * 2 + 1;
  int vr = v * 2 + 2;
  if (pos <= m) {
    pair<int, int> lBorders = getBorders(vl, tl, m, pos, val);
    if (lBorders.second == m) {
      pair<int, int> rBorders = getBorders(vr, m + 1, tr, pos, val);
      if (rBorders.first == m + 1) {
        return make_pair(lBorders.first, rBorders.second);
      }
    }
    return lBorders;
  } else {
    pair<int, int> rBorders = getBorders(vr, m + 1, tr, pos, val);
    if (rBorders.first == m + 1) {
      pair<int, int> lBorders = getBorders(vl, tl, m, pos, val);
      if (lBorders.second == m) {
        return make_pair(lBorders.first, rBorders.second);
      }
    }
    return rBorders;
  }
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    st[v] = p[tl];
    return;
  }
  int m = (tl + tr) >> 1;
  int vl = v * 2 + 1;
  int vr = v * 2 + 2;
  build(vl, tl, m);
  build(vr, m + 1, tr);
  st[v] = min(st[vl], st[vr]);
}
class Fenwick {
 private:
  vector<int> a;
  int sum(int r) {
    int sum = 0;
    while (r >= 0) {
      sum += a[r];
      r &= r + 1;
      --r;
    }
    return sum;
  }

 public:
  Fenwick(int size) { a.resize(size); }
  int sum(int l, int r) { return sum(r) - sum(l - 1); }
  void update(int pos) {
    while (pos < a.size()) {
      a[pos] += 1;
      pos |= pos + 1;
    }
  }
};
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  st.resize(4 * n);
  p.resize(n);
  vector<int> positions(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    positions[p[i]] = i;
  }
  vector<bool> isDel(n + 1, true);
  for (int i = 0; i < k; ++i) {
    int b;
    cin >> b;
    isDel[b] = false;
  }
  build(0, 0, n - 1);
  Fenwick f(n);
  long long ans = 0;
  for (int val = 1; val < n + 1; ++val) {
    if (!isDel[val]) {
      continue;
    }
    int pos = positions[val];
    pair<int, int> borders = getBorders(0, 0, n - 1, pos, val);
    int spaces = f.sum(borders.first, borders.second);
    update(0, 0, n - 1, pos);
    f.update(pos);
    ans += (borders.second - borders.first + 1) - spaces;
  }
  cout << ans << '\n';
  return 0;
}
